Php implements rc4 encryption algorithm
The decryption method of this algorithm can be restored by re-encryption once ..
- /*
- * Rc4 encryption algorithm
- * $ Pwd key
- * $ Data the data to be encrypted
- */
- Function rc4 ($ pwd, $ data) // $ pwd key $ data requires an encrypted string
- {
- $ Key [] = "";
- $ Box [] = "";
- $ Pwd_length = strlen ($ pwd );
- $ Data_length = strlen ($ data );
- For ($ I = 0; $ I <256; $ I ++)
- {
- $ Key [$ I] = ord ($ pwd [$ I % $ pwd_length]);
- $ Box [$ I] = $ I;
- }
- For ($ j = $ I = 0; I I <256; $ I ++)
- {
- $ J = ($ j + $ box [$ I] + $ key [$ I]) % 256;
- $ Tmp = $ box [$ I];
- $ Box [$ I] = $ box [$ j];
- $ Box [$ j] = $ tmp;
- }
- For ($ a = $ j = $ I = 0; $ I <$ data_length; $ I ++)
- {
- $ A = ($ a + 1) % 256;
- $ J = ($ j + $ box [$ a]) % 256;
- $ Tmp = $ box [$ a];
- $ Box [$ a] = $ box [$ j];
- $ Box [$ j] = $ tmp;
- $ K = $ box [($ box [$ a] + $ box [$ j]) % 256)];
- $ Cipher. = chr (ord ($ data [$ I]) ^ $ k );
- }
- Return $ cipher;
- }
|