Last active
December 5, 2017 10:53
-
-
Save shouya/5a962a5ba7c84f6550c96f2e83888532 to your computer and use it in GitHub Desktop.
Having fun with crossword games!
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// extracted from: https://s3.music.126.net/sep/s/2/core.js | |
// rsa.e: exp | |
// rsa.m: modulus | |
function modpow(rsa, str) { | |
for (var f, g, h, i, j, k, l, c = new Array, d = str.length, e = 0; d > e; ) { | |
c[e] = str.charCodeAt(e); | |
e++; | |
for (; 0 != c.length % a.chunkSize; ) { | |
c[e++] = 0; | |
} | |
for (f = c.length, g = "", e = 0; f > e; e += rsa.chunkSize) { | |
for (j = new BigInt, | |
h = 0, | |
i = e; i < e + a.chunkSize; ++h) | |
j.digits[h] = c[i++], | |
j.digits[h] += c[i++] << 8; | |
k = rsa.barrett.powMod(j, rsa.e), | |
l = 16 == rsa.radix ? biToHex(k) : biToString(k, rsa.radix), | |
g += l + " " | |
} | |
} | |
return g.substring(0, g.length - 1) | |
} | |
function RSAKeyPair(encryption_exponent, decryption_exponent, modulus) { | |
this.e = biFromHex(encryption_exponent), | |
this.d = biFromHex(decryption_exponent), | |
this.m = biFromHex(modulus), | |
this.chunkSize = 2 * biHighIndex(modulus), | |
this.radix = 16, | |
this.barrett = new BarrettMu(modulus) | |
} | |
!function() { | |
function gen_aes_key(len) { | |
var symbols = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789", | |
out = ""; | |
for (i = 0; i < key_len; ++i) | |
var x = (Math.random() * symbols.length) | 0; | |
out += symbols.charAt(x); | |
return out; | |
} | |
function aes(data, key) { | |
var key = str_to_bytes(key) | |
, iv = str_to_bytes("0102030405060708") | |
, data = str_to_bytes(data) | |
, result = CryptoJS.AES.encrypt(data, key, { | |
iv: iv, | |
mode: CryptoJS.mode.CBC | |
}); | |
return result.toString() | |
} | |
function rsa(data, exponent, modulus) { | |
var d, e; | |
return setMaxDigits(131), | |
d = new RSAKeyPair(exponent,"",modulus), | |
e = modpow(d, data) | |
} | |
// exponent = 010001 | |
// modulus = 00e0b509f6259df8642dbc35662901477df22677ec152b5ff68ace615bb7b725152b3ab17a876aea8a5aa76d2e417629ec4ee341f56135fccf695280104e0312ecbda92557c93870114af6c9d05c4f7f0c3685b7a46bee255932575cce10b424d813cfe4875d3e82047b97ddef52741d546b8e289dc6935b3ece0462db0a22b8e7 | |
// nounce = 0CoJUm6Qyw8W8jud | |
function enc_req(data, exponent, modulus, nounce) { | |
var h = {}, key = gen_aes_key(16); | |
h.encText = aes(data, nounce); | |
h.encText = aes(h.encText, key); | |
h.encSecKey = rsa(key, exponent, modulus); | |
return h | |
} | |
window.asrsea = enc_req | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment