software:yandex-rsa
Различия
Показаны различия между двумя версиями страницы.
Предыдущая версия справа и слеваПредыдущая версияСледующая версия | Предыдущая версия | ||
software:yandex-rsa [2010/02/03 17:04] – artur | software:yandex-rsa [2017/03/23 21:59] (текущий) – внешнее изменение 127.0.0.1 | ||
---|---|---|---|
Строка 7: | Строка 7: | ||
Base64: http:// | Base64: http:// | ||
- | <code javascript> | + | < |
+ | < | ||
+ | < | ||
+ | <meta http-equiv=" | ||
+ | <script type=' | ||
+ | |||
+ | < | ||
+ | <script> | ||
var test_key = " | var test_key = " | ||
Строка 13: | Строка 20: | ||
+ | function encrypt_yarsa(key, | ||
+ | { | ||
+ | /* Encode string like RSA | ||
+ | * Ported to JS by Artur Khasanov | ||
+ | * EMail: artur[at]hasanov.ru | ||
+ | * Website: http:// | ||
+ | * JS source: http:// | ||
+ | * Ported from Python script written by http:// | ||
+ | */ | ||
+ | var DATA_ARR = new Array(); | ||
+ | var NSTR = new String(key.split('#' | ||
+ | var ESTR = new String(key.split('#' | ||
+ | var N = new String( | ||
+ | var E = new String( | ||
+ | var STEP_SIZE = NSTR.length/ | ||
+ | var prev_crypted = new Array(STEP_SIZE); | ||
+ | var hex_out= new String("" | ||
+ | var plain = new String(); | ||
+ | for(i=0; | ||
+ | console.log(' | ||
+ | for(i=0; i< | ||
+ | tmp = DATA_ARR.slice(i*STEP_SIZE, | ||
+ | for(j=0; | ||
+ | tmp.reverse(); | ||
+ | for(x=0; | ||
+ | pow = powMod(str2bigInt(' | ||
+ | pow_mult = mult(pow, str2bigInt(tmp[x].toString(), | ||
+ | plain = add(plain, pow_mult); | ||
+ | } | ||
+ | plain_pow = powMod(plain, | ||
+ | plain_pow_str = bigInt2str(plain_pow, | ||
+ | hex_result = new Array((NSTR.length - plain_pow_str.length) + 1).join(' | ||
+ | min_x = Math.min(hex_result.length, | ||
+ | console.log(' | ||
+ | for(x=0; | ||
+ | if(tmp.length < 16) hex_out+=" | ||
+ | hex_out += tmp.length.toString(16).toUpperCase() + " | ||
+ | ks = NSTR.length/ | ||
+ | if(ks< | ||
+ | hex_out += ks.toString(16).toUpperCase() + " | ||
+ | hex_out += hex_result; | ||
+ | console.log(' | ||
- | var keyStr | + | } |
+ | result | ||
+ | console.log('# | ||
+ | console.log(' | ||
+ | return result; | ||
+ | } | ||
+ | |||
+ | var keyStr = " | ||
/* Base64 conversion methods. | /* Base64 conversion methods. | ||
* Copyright (c) 2006 by Ali Farhadi. | * Copyright (c) 2006 by Ali Farhadi. | ||
Строка 104: | Строка 160: | ||
if(code> | if(code> | ||
return code; | return code; | ||
- | } | ||
- | |||
- | function encrypt_yarsa(key, | ||
- | { | ||
- | |||
- | var toenc_array = new Array(); | ||
- | var DATA_ARR = new Array(); | ||
- | var ord_str=''; | ||
- | var toenc_str=''; | ||
- | for(i=0; | ||
- | toenc_array[i] = toenc.substr(i, | ||
- | DATA_ARR[i] = ord(toenc_array[i]); | ||
- | ord_str+=',' | ||
} | } | ||
- | var NSTR = key.split('#' | ||
- | var ESTR = key.split('#' | ||
- | var N = new String( | ||
- | var E = new String( | ||
- | var STEP_SIZE = NSTR.length/ | ||
- | // | ||
- | |||
- | var prev_crypted = new Array(24); | ||
- | |||
- | var hex_out= new String("" | ||
- | |||
- | for(i=0; i< | ||
- | { | ||
- | tmp = DATA_ARR.slice(i*STEP_SIZE, | ||
- | tmp_str=''; | ||
- | for(j=0; | ||
- | { | ||
- | tmp[j] = (tmp[j] ^ prev_crypted[j]); | ||
- | tmp_str += ',' | ||
- | } | ||
- | tmp.reverse(); | ||
- | var plain_str = new String('' | ||
- | plain = str2bigInt(plain_str, | ||
- | for(x=0 ; x< | ||
- | { | ||
- | currBase=10; | ||
- | var m1 = new String(' | ||
- | var m2 = new String(x); | ||
- | var n1=str2bigInt(m1, | ||
- | var n2=str2bigInt(m2, | ||
- | var n3=str2bigInt(N, | ||
- | pow1 = powMod(n1, n2, n3); | ||
- | tmp_x = new String(tmp[x]); | ||
- | tmp_x_big = str2bigInt(tmp_x, | ||
- | pow2 = mult(pow1, tmp_x_big); | ||
- | plain = add(plain, pow2); | ||
- | } | ||
- | |||
- | var E1=str2bigInt(E, | ||
- | var N1=str2bigInt(N, | ||
- | plain_pow = powMod(plain, | ||
- | plain_pow_str = bigInt2str(plain_pow, | ||
- | |||
- | // | ||
- | hex_result = new Array((NSTR.length - plain_pow_str.length) + 1).join(' | ||
- | |||
- | min_x = Math.min(hex_result.length, | ||
- | // | ||
- | |||
- | prev_crypted_tmp=''; | ||
- | for(x=0; | ||
- | { | ||
- | prev_crypted[x/ | ||
- | prev_crypted_tmp+=',' | ||
- | } | ||
- | // | ||
- | |||
- | // | ||
- | if(tmp.length < 16) hex_out+=" | ||
- | |||
- | //+ (" | ||
- | hex_out += tmp.length.toString(16).toUpperCase() + " | ||
- | //ks = len(NSTR)/2 | ||
- | ks = NSTR.length/ | ||
- | // | ||
- | if(ks< | ||
- | hex_out += ks.toString(16).toUpperCase() + " | ||
- | hex_out += hex_result; | ||
- | // | ||
- | |||
- | } | ||
- | return base64Encode(hexDecode(hex_out.toLowerCase())).replace(/ | ||
- | } | ||
my_result = encrypt_yarsa(test_key, | my_result = encrypt_yarsa(test_key, | ||
document.write('< | document.write('< | ||
+ | </ | ||
+ | < | ||
+ | </ | ||
+ | </ | ||
</ | </ |
software/yandex-rsa.1265205852.txt.gz · Последнее изменение: 2017/03/23 21:57 (внешнее изменение)