⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 rc4.htm

📁 RC4 算法
💻 HTM
字号:
<html>
<head>
<title>RC4 Encryption</title>
</head>
<body>
    <script language="JavaScript">
/* RC4 symmetric cipher encryption/decryption
* 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://farhadi.ir/
*/

/**
* Encrypt given plain text using the key with RC4 algorithm.
* All parameters and return value are in binary format.
*
* @param string key - secret key for encryption
* @param string pt - plain text to be encrypted
* @return string
*/
function rc4Encrypt(key, pt) {
    s = new Array();
    for (var i=0; i<256; i++) {
        s[i] = i;
    }
    var j = 0;
    var x;
    for (i=0; i<256; i++) {
        j = (j + s[i] + key.charCodeAt(i % key.length)) % 256;
        x = s[i];
        s[i] = s[j];
        s[j] = x;
    }
    i = 0;
    j = 0;
    var ct = '';
    for (var y=0; y<pt.length; y++) {
        i = (i + 1) % 256;
        j = (j + s[i]) % 256;
        x = s[i];
        s[i] = s[j];
        s[j] = x;
        ct += String.fromCharCode(pt.charCodeAt(y) ^ s[(s[i] + s[j]) % 256]);
    }
    return ct;
}

/**
* Decrypt given cipher text using the key with RC4 algorithm.
* All parameters and return value are in binary format.
*
* @param string key - secret key for decryption
* @param string ct - cipher text to be decrypted
* @return string
*/
function rc4Decrypt(key, ct) {
    return rc4Encrypt(key, ct);
}
    </script>
              <script language="JavaScript">
                <!--
                  function e() {
                     document.rc4.text.value=escape(rc4Encrypt(document.rc4.key.value,document.rc4.text.value))
                  }
                  function d() {
                     document.rc4.text.value=(rc4Decrypt(document.rc4.key.value,unescape(document.rc4.text.value)))
                  }
                -->
              </script>

    <h3>RC4 Encryption (input text for both field):</h3>
    <form method="POST" name="rc4">
      <div align="center">
        <table border="0">
          <tr>
            <td align="right">
              Key:
            </td>
            <td>
              <input type="text" size="60" name="key" value="">
            </td>
          </tr>
          <tr>
            <td align="right">
              Text:
            </td>
            <td>
              <textarea name="text" rows="6" cols="70"></textarea>
            </td>
          </tr>
          <tr>
            <td>
              <p align="center">
                <input type="button" name="B1" value="Encrypt" onclick="e()">
                <input type="button" name="B2" value="Decrypt" onclick="d()">
              </p>
            </td>
          </tr>
        </table>
      </div>
    </form>
</body>
</html>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -