Exetools  

Go Back   Exetools > General > General Discussion

Notices

Reply
 
Thread Tools Display Modes
  #1  
Old 12-23-2021, 01:31
raduga_fb raduga_fb is offline
Family
 
Join Date: Nov 2012
Posts: 73
Rept. Given: 3
Rept. Rcvd 127 Times in 23 Posts
Thanks Given: 2
Thanks Rcvd at 132 Times in 33 Posts
raduga_fb Reputation: 100-199 raduga_fb Reputation: 100-199
RC4

Code:
 public class RC4
    {
        public static byte[] Encrypt(byte[] pwd, byte[] data)
        {
            int a, i, j, k, tmp;
            int[] key, box;
            byte[] cipher;

            key = new int[256];
            box = new int[256];
            cipher = new byte[data.Length];

            for (i = 0; i < 256; i++)
            {
                key[i] = pwd[i % pwd.Length];
                box[i] = i;
            }
            for (j = i = 0; 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 %= 256;
                j += box[a];
                j %= 256;
                tmp = box[a];
                box[a] = box[j];
                box[j] = tmp;
                k = box[((box[a] + box[j]) % 256)];
                cipher[i] = (byte)(data[i] ^ k);
            }
            return cipher;
        }

        public static byte[] Decrypt(byte[] pwd, byte[] data)
        {
            return Encrypt(pwd, data);
        }

    }
Reply With Quote
The Following User Gave Reputation+1 to raduga_fb For This Useful Post:
niculaita (12-23-2021)
The Following 2 Users Say Thank You to raduga_fb For This Useful Post:
foil (12-24-2021), niculaita (12-23-2021)
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Can the bit0 mask in port 0x21 stop generating int 0x08? BlackWhite General Discussion 0 03-19-2021 22:53


All times are GMT +8. The time now is 18:04.


Always Your Best Friend: Aaron, JMI, ahmadmansoor, ZeNiX, chessgod101
( Since 1998 )