pvpgn-twilight 0.0.8 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (5) hide show
  1. data/Changes +7 -1
  2. data/ext/extconf.rb +8 -6
  3. data/ext/pvpgn.cpp +206 -206
  4. data/pvpgn-twilight.gemspec +13 -13
  5. metadata +1 -1
data/Changes CHANGED
@@ -25,4 +25,10 @@ Version 0.0.7
25
25
 
26
26
  Version 0.0.8
27
27
  - Added G++ compiler specifier
28
- - GitHub repository now defunkt, use GemCutter instead
28
+ - GitHub repository now defunkt, use GemCutter instead
29
+
30
+ Version 0.0.9
31
+ - extconf.rb updates
32
+
33
+ Version 0.1.0
34
+ - Changed text formats to UNIX style
data/ext/extconf.rb CHANGED
@@ -1,6 +1,8 @@
1
- # Loads mkmf which is used to make makefiles for Ruby extensions
2
- require 'mkmf'
3
-
4
- # Do the work
5
- cpp_command('g++')
6
- create_makefile('pvpgn')
1
+ # Loads mkmf which is used to make makefiles for Ruby extensions
2
+ require 'mkmf'
3
+
4
+ # Do the work
5
+ $CC = 'g++'
6
+ $CXX = $CC
7
+ cpp_command('g++')
8
+ create_makefile('pvpgn')
data/ext/pvpgn.cpp CHANGED
@@ -1,206 +1,206 @@
1
- #define PVPGN_TWILIGHT_VERSION "0.0.6"
2
-
3
- #ifdef __TEST__
4
- #include <iostream>
5
- #else
6
- #include "ruby.h"
7
- #endif
8
-
9
- typedef unsigned int t_uint32;
10
- typedef signed int t_sint32;
11
-
12
- #define ROTL(x,n,w) (((x)<<((n)&(w-1))) | ((x)>>(((-(n))&(w-1)))))
13
-
14
- #define ROTL32(x,n) ROTL(x,n,32)
15
- #define ROTL16(x,n) ROTL(x,n,16)
16
-
17
- static void PVPGN_Hash(t_uint32* pHash, t_uint32* pTemp)
18
- {
19
- t_uint32 i;
20
-
21
- for(i = 0; i < 64; i++)
22
- pTemp[i + 16] = ROTL32(1,pTemp[i] ^ pTemp[i + 8] ^ pTemp[i + 2] ^ pTemp[i + 13]);
23
-
24
- t_uint32 a = pHash[0];
25
- t_uint32 b = pHash[1];
26
- t_uint32 c = pHash[2];
27
- t_uint32 d = pHash[3];
28
- t_uint32 e = pHash[4];
29
- t_uint32 g;
30
-
31
- for(i = 0; i < 20; i++)
32
- {
33
- g = pTemp[i] + ROTL32(a,5) + e + ((b & c) | (~b & d)) + 0x5a827999;
34
- e = d;
35
- d = c;
36
- c = ROTL32(b,30);
37
- b = a;
38
- a = g;
39
- }
40
-
41
- for(; i < 40; i++)
42
- {
43
- g = (d ^ c ^ b) + e + ROTL32(g,5) + pTemp[i] + 0x6ed9eba1;
44
- e = d;
45
- d = c;
46
- c = ROTL32(b,30);
47
- b = a;
48
- a = g;
49
- }
50
-
51
- for (; i < 60; i++)
52
- {
53
- g = pTemp[i] + ROTL32(g,5) + e + ((c & b) | (d & c) | (d & b)) - 0x70e44324;
54
- e = d;
55
- d = c;
56
- c = ROTL32(b,30);
57
- b = a;
58
- a = g;
59
- }
60
-
61
- for (; i < 80; i++)
62
- {
63
- g = (d ^ c ^ b) + e + ROTL32(g,5) + pTemp[i] - 0x359d3e2a;
64
- e = d;
65
- d = c;
66
- c = ROTL32(b,30);
67
- b = a;
68
- a = g;
69
- }
70
-
71
- pHash[0] += g;
72
- pHash[1] += b;
73
- pHash[2] += c;
74
- pHash[3] += d;
75
- pHash[4] += e;
76
- }
77
-
78
- static void PVPGN_Set16(t_uint32* pDest, const unsigned char* pSource, t_sint32 nSize)
79
- {
80
- if(pDest == NULL || pSource == NULL || nSize < 0)
81
- return;
82
-
83
- t_uint32 i, dwPos;
84
- for(dwPos = 0, i = 0; i < 16; i++)
85
- {
86
- pDest[i] = 0;
87
- if(dwPos < nSize)
88
- pDest[i] |= ((t_uint32)pSource[dwPos]);
89
-
90
- dwPos++;
91
- if(dwPos < nSize)
92
- pDest[i] |= ((t_uint32)pSource[dwPos]) << 8;
93
-
94
- dwPos++;
95
- if(dwPos < nSize)
96
- pDest[i] |= ((t_uint32)pSource[dwPos]) << 16;
97
-
98
- dwPos++;
99
- if(dwPos < nSize)
100
- pDest[i] |= ((t_uint32)pSource[dwPos]) << 24;
101
-
102
- dwPos++;
103
- }
104
- }
105
-
106
- static void UTILITY_ToLower(char* pString)
107
- {
108
- if(pString == NULL)
109
- return;
110
-
111
- char nChar = 0;
112
- while((nChar = *pString))
113
- *pString++ = ((nChar < 'A' || nChar > 'Z') ? nChar : (nChar + 0x20));
114
- }
115
-
116
- static void UTILITY_HexToText(char* pBuffer, t_uint32 dwHex, t_uint32 bUpper = 0)
117
- {
118
- if(pBuffer == NULL)
119
- return;
120
-
121
- static const char szHex[] = {'0','1','2','3','4','5','6','7','8','9','a','b','c','d','e','f'};
122
- static const char szHexU[] = {'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'};
123
- int i;
124
- if(!bUpper)
125
- {
126
- for(i = 7; i > -1; i--)
127
- {
128
- int nChar = dwHex % 16;
129
- dwHex >>= 4;
130
- pBuffer[i] = szHex[nChar];
131
- }
132
- }
133
- else
134
- {
135
- for(i = 7; i > -1; i--)
136
- {
137
- int nChar = dwHex % 16;
138
- dwHex >>= 4;
139
- pBuffer[i] = szHexU[nChar];
140
- }
141
- }
142
- }
143
-
144
- static char* PVPGN_CreateHash(char* pHash, t_sint32 nSize)
145
- {
146
- if(pHash == NULL || nSize < 1)
147
- return NULL;
148
-
149
- t_uint32 dwLength = 0, i;
150
- unsigned char* pData = (unsigned char*)pHash;
151
- char pHashOut[41];
152
- t_uint32 dwHash[5] = {0x67452301,0xefcdab89,0x98badcfe,0x10325476,0xc3d2e1f0};
153
- t_uint32 dwTemp[80];
154
-
155
- pHashOut[40] = 0;
156
- UTILITY_ToLower(pHash);
157
- while(nSize > 0)
158
- {
159
- dwLength = (nSize > 64) ? 64 : nSize;
160
- PVPGN_Set16(dwTemp,pData,dwLength);
161
- PVPGN_Hash(dwHash,dwTemp);
162
- nSize -= dwLength;
163
- pData += dwLength;
164
- }
165
-
166
- for(i = 0; i < 5; i++)
167
- UTILITY_HexToText(&pHashOut[i * 8],dwHash[i]);
168
-
169
- return pHashOut;
170
- }
171
- #ifdef __TEST__
172
- int main(int argc, char *argv[])
173
- {
174
- std::string sInput;
175
- std::cout << "Please Enter Password: ";
176
- std::cin >> sInput;
177
- std::cout << "Hash: " << PVPGN_CreateHash((char*)sInput.c_str(),sInput.size()) << std::endl;
178
- system("PAUSE");
179
- return 0;
180
- }
181
- #else
182
- /*
183
- * call-seq:
184
- * PVPGN.BNHash(string_to_hash)
185
- *
186
- * Creates the PVPGN hash for the give string, it is automatically
187
- * converted to a lower case string, the input is also automatically
188
- * converted to lower case
189
- */
190
- static VALUE __cdecl RUBY_BNHash(int argc, VALUE* argv, VALUE klass)
191
- {
192
- VALUE vPassword;
193
- if(argc != 1)
194
- rb_raise(rb_eRuntimeError,"Invalid Amount of Arguments");
195
-
196
- vPassword = argv[0];
197
- char* szPass = StringValuePtr(vPassword);
198
- return rb_str_new2(PVPGN_CreateHash(szPass,strlen(szPass)));
199
- }
200
-
201
- void Init_pvpgn()
202
- {
203
- static VALUE mPVPGN = rb_define_module("PVPGN");
204
- rb_define_module_function(mPVPGN,"BNHash",(VALUE (*)(...))RUBY_BNHash,-1);
205
- }
206
- #endif
1
+ #define PVPGN_TWILIGHT_VERSION "0.1.0"
2
+
3
+ #ifdef __TEST__
4
+ #include <iostream>
5
+ #else
6
+ #include "ruby.h"
7
+ #endif
8
+
9
+ typedef unsigned int t_uint32;
10
+ typedef signed int t_sint32;
11
+
12
+ #define ROTL(x,n,w) (((x)<<((n)&(w-1))) | ((x)>>(((-(n))&(w-1)))))
13
+
14
+ #define ROTL32(x,n) ROTL(x,n,32)
15
+ #define ROTL16(x,n) ROTL(x,n,16)
16
+
17
+ static void PVPGN_Hash(t_uint32* pHash, t_uint32* pTemp)
18
+ {
19
+ t_uint32 i;
20
+
21
+ for(i = 0; i < 64; i++)
22
+ pTemp[i + 16] = ROTL32(1,pTemp[i] ^ pTemp[i + 8] ^ pTemp[i + 2] ^ pTemp[i + 13]);
23
+
24
+ t_uint32 a = pHash[0];
25
+ t_uint32 b = pHash[1];
26
+ t_uint32 c = pHash[2];
27
+ t_uint32 d = pHash[3];
28
+ t_uint32 e = pHash[4];
29
+ t_uint32 g;
30
+
31
+ for(i = 0; i < 20; i++)
32
+ {
33
+ g = pTemp[i] + ROTL32(a,5) + e + ((b & c) | (~b & d)) + 0x5a827999;
34
+ e = d;
35
+ d = c;
36
+ c = ROTL32(b,30);
37
+ b = a;
38
+ a = g;
39
+ }
40
+
41
+ for(; i < 40; i++)
42
+ {
43
+ g = (d ^ c ^ b) + e + ROTL32(g,5) + pTemp[i] + 0x6ed9eba1;
44
+ e = d;
45
+ d = c;
46
+ c = ROTL32(b,30);
47
+ b = a;
48
+ a = g;
49
+ }
50
+
51
+ for (; i < 60; i++)
52
+ {
53
+ g = pTemp[i] + ROTL32(g,5) + e + ((c & b) | (d & c) | (d & b)) - 0x70e44324;
54
+ e = d;
55
+ d = c;
56
+ c = ROTL32(b,30);
57
+ b = a;
58
+ a = g;
59
+ }
60
+
61
+ for (; i < 80; i++)
62
+ {
63
+ g = (d ^ c ^ b) + e + ROTL32(g,5) + pTemp[i] - 0x359d3e2a;
64
+ e = d;
65
+ d = c;
66
+ c = ROTL32(b,30);
67
+ b = a;
68
+ a = g;
69
+ }
70
+
71
+ pHash[0] += g;
72
+ pHash[1] += b;
73
+ pHash[2] += c;
74
+ pHash[3] += d;
75
+ pHash[4] += e;
76
+ }
77
+
78
+ static void PVPGN_Set16(t_uint32* pDest, const unsigned char* pSource, t_sint32 nSize)
79
+ {
80
+ if(pDest == NULL || pSource == NULL || nSize < 0)
81
+ return;
82
+
83
+ t_uint32 i, dwPos;
84
+ for(dwPos = 0, i = 0; i < 16; i++)
85
+ {
86
+ pDest[i] = 0;
87
+ if(dwPos < nSize)
88
+ pDest[i] |= ((t_uint32)pSource[dwPos]);
89
+
90
+ dwPos++;
91
+ if(dwPos < nSize)
92
+ pDest[i] |= ((t_uint32)pSource[dwPos]) << 8;
93
+
94
+ dwPos++;
95
+ if(dwPos < nSize)
96
+ pDest[i] |= ((t_uint32)pSource[dwPos]) << 16;
97
+
98
+ dwPos++;
99
+ if(dwPos < nSize)
100
+ pDest[i] |= ((t_uint32)pSource[dwPos]) << 24;
101
+
102
+ dwPos++;
103
+ }
104
+ }
105
+
106
+ static void UTILITY_ToLower(char* pString)
107
+ {
108
+ if(pString == NULL)
109
+ return;
110
+
111
+ char nChar = 0;
112
+ while((nChar = *pString))
113
+ *pString++ = ((nChar < 'A' || nChar > 'Z') ? nChar : (nChar + 0x20));
114
+ }
115
+
116
+ static void UTILITY_HexToText(char* pBuffer, t_uint32 dwHex, t_uint32 bUpper = 0)
117
+ {
118
+ if(pBuffer == NULL)
119
+ return;
120
+
121
+ static const char szHex[] = {'0','1','2','3','4','5','6','7','8','9','a','b','c','d','e','f'};
122
+ static const char szHexU[] = {'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'};
123
+ int i;
124
+ if(!bUpper)
125
+ {
126
+ for(i = 7; i > -1; i--)
127
+ {
128
+ int nChar = dwHex % 16;
129
+ dwHex >>= 4;
130
+ pBuffer[i] = szHex[nChar];
131
+ }
132
+ }
133
+ else
134
+ {
135
+ for(i = 7; i > -1; i--)
136
+ {
137
+ int nChar = dwHex % 16;
138
+ dwHex >>= 4;
139
+ pBuffer[i] = szHexU[nChar];
140
+ }
141
+ }
142
+ }
143
+
144
+ static char* PVPGN_CreateHash(char* pHash, t_sint32 nSize)
145
+ {
146
+ if(pHash == NULL || nSize < 1)
147
+ return NULL;
148
+
149
+ t_uint32 dwLength = 0, i;
150
+ unsigned char* pData = (unsigned char*)pHash;
151
+ char pHashOut[41];
152
+ t_uint32 dwHash[5] = {0x67452301,0xefcdab89,0x98badcfe,0x10325476,0xc3d2e1f0};
153
+ t_uint32 dwTemp[80];
154
+
155
+ pHashOut[40] = 0;
156
+ UTILITY_ToLower(pHash);
157
+ while(nSize > 0)
158
+ {
159
+ dwLength = (nSize > 64) ? 64 : nSize;
160
+ PVPGN_Set16(dwTemp,pData,dwLength);
161
+ PVPGN_Hash(dwHash,dwTemp);
162
+ nSize -= dwLength;
163
+ pData += dwLength;
164
+ }
165
+
166
+ for(i = 0; i < 5; i++)
167
+ UTILITY_HexToText(&pHashOut[i * 8],dwHash[i]);
168
+
169
+ return pHashOut;
170
+ }
171
+ #ifdef __TEST__
172
+ int main(int argc, char *argv[])
173
+ {
174
+ std::string sInput;
175
+ std::cout << "Please Enter Password: ";
176
+ std::cin >> sInput;
177
+ std::cout << "Hash: " << PVPGN_CreateHash((char*)sInput.c_str(),sInput.size()) << std::endl;
178
+ system("PAUSE");
179
+ return 0;
180
+ }
181
+ #else
182
+ /*
183
+ * call-seq:
184
+ * PVPGN.BNHash(string_to_hash)
185
+ *
186
+ * Creates the PVPGN hash for the give string, it is automatically
187
+ * converted to a lower case string, the input is also automatically
188
+ * converted to lower case
189
+ */
190
+ static VALUE __cdecl RUBY_BNHash(int argc, VALUE* argv, VALUE klass)
191
+ {
192
+ VALUE vPassword;
193
+ if(argc != 1)
194
+ rb_raise(rb_eRuntimeError,"Invalid Amount of Arguments");
195
+
196
+ vPassword = argv[0];
197
+ char* szPass = StringValuePtr(vPassword);
198
+ return rb_str_new2(PVPGN_CreateHash(szPass,strlen(szPass)));
199
+ }
200
+
201
+ void Init_pvpgn()
202
+ {
203
+ static VALUE mPVPGN = rb_define_module("PVPGN");
204
+ rb_define_module_function(mPVPGN,"BNHash",(VALUE (*)(...))RUBY_BNHash,-1);
205
+ }
206
+ #endif
@@ -1,14 +1,14 @@
1
- Gem::Specification.new do |s|
2
- s.name = %q{pvpgn-twilight}
3
- s.version = "0.0.8"
4
- s.date = %q{2009-12-02}
5
- s.authors = ["Lorenzo Boccetti"]
6
- s.email = %q{necrolis@gamil.com}
7
- s.summary = %q{A ruby interface for Twilight PVPGN}
8
- s.homepage = %q{http://www.twilightgaming.co.za}
9
- s.description = %q{PVPGN-Twilight allows ruby scripts to communicate with pvpgn, while providing faster varients of certain functions, like hashing}
10
- s.files = ["pvpgn-twilight.gemspec","ext/pvpgn.cpp","examples/pvpgn_test.rb","ext/extconf.rb","Changes","docs/pvpgn-twilight.txt","pvpgn-twilight.gemspec"]
11
- s.extensions << 'ext/extconf.rb'
12
- s.has_rdoc = true
13
- s.extra_rdoc_files = ["Changes","ext/pvpgn.cpp","docs/pvpgn-twilight.txt"]
1
+ Gem::Specification.new do |s|
2
+ s.name = %q{pvpgn-twilight}
3
+ s.version = "0.1.0"
4
+ s.date = %q{2009-12-02}
5
+ s.authors = ["Lorenzo Boccetti"]
6
+ s.email = %q{necrolis@gamil.com}
7
+ s.summary = %q{A ruby interface for Twilight PVPGN}
8
+ s.homepage = %q{http://www.twilightgaming.co.za}
9
+ s.description = %q{PVPGN-Twilight allows ruby scripts to communicate with pvpgn, while providing faster varients of certain functions, like hashing}
10
+ s.files = ["pvpgn-twilight.gemspec","ext/pvpgn.cpp","examples/pvpgn_test.rb","ext/extconf.rb","Changes","docs/pvpgn-twilight.txt","pvpgn-twilight.gemspec"]
11
+ s.extensions << 'ext/extconf.rb'
12
+ s.has_rdoc = true
13
+ s.extra_rdoc_files = ["Changes","ext/pvpgn.cpp","docs/pvpgn-twilight.txt"]
14
14
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pvpgn-twilight
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.8
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Lorenzo Boccetti