»
Tiếng AnhTiếng PhápTiếng Việt

In - Mã hóa và giải mã - JavaScriptBank.com

Phiên bản đầy đủ: jsB@nk » Bảo mật » Mã hóa » Mã hóa và giải mã
URL: https://www.javascriptbank.com/encode-decode.html

Mã hóa và giải mã © JavaScriptBank.comMột phương pháp khác để mã hóa và giải mã dữ liệu của bạn với một giá trị khóa nào đó.

Phiên bản đầy đủ: jsB@nk » Bảo mật » Mã hóa » Mã hóa và giải mã
URL: https://www.javascriptbank.com/encode-decode.html



JavaScript
<SCRIPT LANGUAGE="JavaScript">// Colin Russell (niloc12@hotmail.com)<!-- Beginvar wt = ""; //temporary holdervar et = ""; //encoded textvar all = "";var all2 = "";var alpha2 = "abcdefghijklmnopqrstuvwxyz";var a = "a"; var b = "b"; var c = "c"; var d = "d";var e = "e"; var f = "f"; var g = "g"; var h = "h";var i = "i"; var j = "j"; var k = "k"; var l = "l";var m = "m"; var n = "n"; var o = "o"; var p = "p";var q = "q"; var r = "r"; var s = "s"; var t = "t";var u = "u"; var v = "v"; var w = "w"; var x = "x";var y = "y"; var z = "z";var alpha = new Array('a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j','k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x','y', 'z');function encode() {wt = "";et = "";all = "";var theText = document.f1.ta1.value.toLowerCase();var num = document.f1.tb1.value;i2 = 0;for (i = 0; i < num; i++) { i2 = i2 + 1;if (i2 == 26) i2 = 0;}a = alpha[i2]; i2 = next(i2);b = alpha[i2]; i2 = next(i2);c = alpha[i2]; i2 = next(i2);d = alpha[i2]; i2 = next(i2);e = alpha[i2]; i2 = next(i2);f = alpha[i2]; i2 = next(i2);g = alpha[i2]; i2 = next(i2);h = alpha[i2]; i2 = next(i2);i = alpha[i2]; i2 = next(i2);j = alpha[i2]; i2 = next(i2);k = alpha[i2]; i2 = next(i2);l = alpha[i2]; i2 = next(i2);m = alpha[i2]; i2 = next(i2);n = alpha[i2]; i2 = next(i2);o = alpha[i2]; i2 = next(i2);p = alpha[i2]; i2 = next(i2);q = alpha[i2]; i2 = next(i2);r = alpha[i2]; i2 = next(i2);s = alpha[i2]; i2 = next(i2);t = alpha[i2]; i2 = next(i2);u = alpha[i2]; i2 = next(i2);v = alpha[i2]; i2 = next(i2);w = alpha[i2]; i2 = next(i2);x = alpha[i2]; i2 = next(i2);y = alpha[i2]; i2 = next(i2);z = alpha[i2]; i2 = next(i2);var all = a+b+c+d+e+f+g+h+i+j+k+l+m+n+o+p+q+r+s+t+u+v+w+x+y+z;all = all.split("");encode2(all);}function next(x) {if (x == 25) x = -1;x = x + 1;return x;}function encode2(all2) {var temp2 = document.f1.ta1.value.toLowerCase();temp2 = temp2.split("");var q = 0;while (q < temp2.length) { wt = temp2[q];var where = alpha2.indexOf(wt);if (where == -1) { et += wt; }if (where != -1) { et += all2[where]; }q = q + 1;}document.f1.ta1.value = et;}function decode() {wt = "";et = "";all = "";all3 = "";var theText = document.f1.ta1.value.toLowerCase();var num = document.f1.tb1.value;i2 = 0;for (i = 0; i < num; i++) {i2 = i2 + 1;if (i2 == 26) i2 = 0;}a = alpha[i2]; i2 = next(i2);b = alpha[i2]; i2 = next(i2);c = alpha[i2]; i2 = next(i2);d = alpha[i2]; i2 = next(i2);e = alpha[i2]; i2 = next(i2);f = alpha[i2]; i2 = next(i2);g = alpha[i2]; i2 = next(i2);h = alpha[i2]; i2 = next(i2);i = alpha[i2]; i2 = next(i2);j = alpha[i2]; i2 = next(i2);k = alpha[i2]; i2 = next(i2);l = alpha[i2]; i2 = next(i2);m = alpha[i2]; i2 = next(i2);n = alpha[i2]; i2 = next(i2);o = alpha[i2]; i2 = next(i2);p = alpha[i2]; i2 = next(i2);q = alpha[i2]; i2 = next(i2);r = alpha[i2]; i2 = next(i2);s = alpha[i2]; i2 = next(i2);t = alpha[i2]; i2 = next(i2);u = alpha[i2]; i2 = next(i2);v = alpha[i2]; i2 = next(i2);w = alpha[i2]; i2 = next(i2);x = alpha[i2]; i2 = next(i2);y = alpha[i2]; i2 = next(i2);z = alpha[i2]; i2 = next(i2);var all = a+b+c+d+e+f+g+h+i+j+k+l+m+n+o+p+q+r+s+t+u+v+w+x+y+z;all3 = all;all = all.split("");decode2(all3);}function decode2(all2) { var alpha2 = "abcdefghijklmnopqrstuvwxyz";alpha2 = alpha2.split("");var temp2 = document.f1.ta1.value.toLowerCase();temp2 = temp2.split("");var v = 0;while (v < temp2.length) {wt = temp2[v];var where = all2.indexOf(wt);if (where == -1) { et += wt; }if (where != -1) { et += alpha2[where]; }v = v + 1;}document.f1.ta1.value = et;}// End --></script><!--    This script downloaded from www.JavaScriptBank.com    Come to view and download over 2000+ free javascript at www.JavaScriptBank.com-->


HTML
<form name=f1><textarea name=ta1 cols=40 rows=10></textarea><p>Key Value: <input type="text" size=10 name="tb1"value=""><br><input type="button" value="Encode Message" onClick="encode();return false;"><input type="button" value="Decode Message" onClick="decode();return false;"></form><!--    This script downloaded from www.JavaScriptBank.com    Come to view and download over 2000+ free javascript at www.JavaScriptBank.com-->