software:yandex-rsa
Различия
Показаны различия между двумя версиями страницы.
Предыдущая версия справа и слеваПредыдущая версияСледующая версия | Предыдущая версия | ||
software:yandex-rsa [2010/02/03 16:59] – artur | software:yandex-rsa [2017/03/23 21:59] (текущий) – внешнее изменение 127.0.0.1 | ||
---|---|---|---|
Строка 3: | Строка 3: | ||
BigInt.js: http:// | BigInt.js: http:// | ||
+ | Функции для декодирования: | ||
+ | hex: http:// | ||
+ | Base64: http:// | ||
- | < | + | < |
+ | < | ||
+ | < | ||
+ | <meta http-equiv=" | ||
+ | <script type=' | ||
+ | < | ||
+ | < | ||
+ | var test_key = " | ||
+ | var test_toenc = ' | ||
+ | |||
+ | 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(' | ||
+ | |||
+ | } | ||
+ | result = base64Encode(hexDecode(hex_out.toLowerCase())).replace(/ | ||
+ | console.log('# | ||
+ | console.log(' | ||
+ | return result; | ||
+ | } | ||
+ | |||
+ | |||
+ | var keyStr = " | ||
+ | /* Base64 conversion methods. | ||
+ | * Copyright (c) 2006 by Ali Farhadi. | ||
+ | * released under the terms of the Gnu Public License. | ||
+ | * see the GPL for details. | ||
+ | * | ||
+ | * Email: ali[at]farhadi[dot]ir | ||
+ | * Website: http:// | ||
+ | */ | ||
+ | |||
+ | //Encodes data to Base64 format | ||
+ | function base64Encode(data){ | ||
+ | if (typeof(btoa) == ' | ||
+ | var b64_map = ' | ||
+ | var byte1, byte2, byte3; | ||
+ | var ch1, ch2, ch3, ch4; | ||
+ | var result = new Array(); //array is used instead of string because in most of browsers working with large arrays is faster than working with large strings | ||
+ | var j=0; | ||
+ | for (var i=0; i< | ||
+ | byte1 = data.charCodeAt(i); | ||
+ | byte2 = data.charCodeAt(i+1); | ||
+ | byte3 = data.charCodeAt(i+2); | ||
+ | ch1 = byte1 >> 2; | ||
+ | ch2 = ((byte1 & 3) << 4) | (byte2 >> 4); | ||
+ | ch3 = ((byte2 & 15) << 2) | (byte3 >> 6); | ||
+ | ch4 = byte3 & 63; | ||
+ | |||
+ | if (isNaN(byte2)) { | ||
+ | ch3 = ch4 = 64; | ||
+ | } else if (isNaN(byte3)) { | ||
+ | ch4 = 64; | ||
+ | } | ||
+ | |||
+ | result[j++] = b64_map.charAt(ch1)+b64_map.charAt(ch2)+b64_map.charAt(ch3)+b64_map.charAt(ch4); | ||
+ | } | ||
+ | |||
+ | return result.join('' | ||
+ | } | ||
+ | |||
+ | |||
+ | /* Hexadecimal conversion methods. | ||
+ | * Copyright (c) 2006 by Ali Farhadi. | ||
+ | * released under the terms of the Gnu Public License. | ||
+ | * see the GPL for details. | ||
+ | * | ||
+ | * Email: ali[at]farhadi[dot]ir | ||
+ | * Website: http:// | ||
+ | */ | ||
+ | |||
+ | //Encodes data to Hex(base16) format | ||
+ | function hexEncode(data){ | ||
+ | var b16_digits = ' | ||
+ | var b16_map = new Array(); | ||
+ | for (var i=0; i<256; i++) { | ||
+ | b16_map[i] = b16_digits.charAt(i >> 4) + b16_digits.charAt(i & 15); | ||
+ | } | ||
+ | |||
+ | var result = new Array(); | ||
+ | for (var i=0; i< | ||
+ | result[i] = b16_map[data.charCodeAt(i)]; | ||
+ | } | ||
+ | |||
+ | return result.join('' | ||
+ | } | ||
+ | |||
+ | //Decodes Hex(base16) formated data | ||
+ | function hexDecode(data){ | ||
+ | var b16_digits = ' | ||
+ | var b16_map = new Array(); | ||
+ | for (var i=0; i<256; i++) { | ||
+ | b16_map[b16_digits.charAt(i >> 4) + b16_digits.charAt(i & 15)] = String.fromCharCode(i); | ||
+ | } | ||
+ | if (!data.match(/ | ||
+ | |||
+ | if (data.length % 2) data = ' | ||
+ | |||
+ | var result = new Array(); | ||
+ | var j=0; | ||
+ | for (var i=0; i< | ||
+ | result[j++] = b16_map[data.substr(i, | ||
+ | } | ||
+ | |||
+ | return result.join('' | ||
+ | } | ||
+ | |||
+ | function ord( string ) { // Return ASCII value of character | ||
+ | code = string.charCodeAt(0); | ||
+ | if(code> | ||
+ | return code; | ||
+ | } | ||
+ | |||
+ | my_result = encrypt_yarsa(test_key, | ||
+ | document.write('< | ||
+ | </ | ||
+ | < | ||
+ | </ | ||
+ | </ | ||
</ | </ |
software/yandex-rsa.1265205557.txt.gz · Последнее изменение: 2017/03/23 21:57 (внешнее изменение)