Skip to content

Commit

Permalink
node.js implementation working identically to python's
Browse files Browse the repository at this point in the history
  • Loading branch information
MaxDesiatov committed Apr 20, 2013
1 parent b2109bc commit 9dbc6d1
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 8 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ AquaticPrime Developer.app
.DS_Store
.idea
*.xcuserstate
node_modules
28 changes: 26 additions & 2 deletions Source/NodeJS/aquatic_prime.coffee
Original file line number Diff line number Diff line change
@@ -1,5 +1,29 @@
_ = require 'underscore'
crypto = require 'crypto'
bigint = require 'bigint'

pubKey = 'E9DBF6A4F6B443282117C6D5E9255F6735DC45DBCB9FA3CABD0F082689B4A25504A2340E2F2F541BF2CE7987491EC541E8B5496BB6AF235F18B6C31F37CA68B430431E41611E93DCFBE40EB7D3C726E74B9D68B9867706A5E0CBD44E0B8863AAC3D2FDBF3CD57B10C3E90039E966F789CC8CBCB1CEBBD2EB95FF5F05E48F37A3'
privKey = '9BE7F9C34F22D770160FD9E3F0C394EF793D83E7DD1517DC7E0A056F06786C38ADC1780974CA3812A1DEFBAF8614838145CE30F279CA1794BB248214CFDC45CC2EFAD1A84D0B8B442D71623486EC36DF6036A4AD8CD319743E7BCF0ECFEA8D0955B1305E42FE30F042D67A9317F10FF3CD2EDFB1D003896EF7791742199348AB'

powmod = (x, a, m) ->
r = bigint 1
while a.gt bigint 0
if a.mod(bigint 2).eq bigint 1
r = r.mul(x).mod m
a = a.shiftRight 1
x = x.mul(x).mod m
r

getSignature = (licensee) ->
total = _(licensee).chain().keys().invoke('toLowerCase').value().sort().join ''
total = (licensee[k] for key in (k for k of licensee).sort()).join ''
hash = crypto.createHash 'sha1'
hash.update total, 'utf8'
digest = hash.digest 'hex'
paddedHash = '0001'
for i in [0..104]
paddedHash += 'ff'
paddedHash += '00' + digest

signature = powmod(bigint(paddedHash, 16),
bigint(privKey, 16), bigint(pubKey, 16)).toBuffer().toString 'base64'

console.log getSignature name: 'koen'
8 changes: 2 additions & 6 deletions Source/NodeJS/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "aquatic-prime",
"preferGlobal": false,
"version": "0.0.0",
"version": "0.0.1",
"author": "Max Desyatov <max.desyatov@gmail.com>",
"description": "node.js port of AquaticPrime license generator",
"contributors": [
Expand All @@ -21,15 +21,11 @@
],
"dependencies": {
"coffee-script": "1.6.x",
"underscore": "1.4.x"
"bigint": "~0.4.2"
},
"analyze": false,
"license": "MIT",
"engines": {
"node": ">=0.10"
},
"devDependencies": {
"nodeunit": "0.8.x",
"grunt-contrib-nodeunit": "~0.1.2"
}
}

0 comments on commit 9dbc6d1

Please sign in to comment.