fn new(key: &[u8]) -> RC4Cipher {
        let k = key.len();
        if k < 1 || k > 256 {
            panic!("Key size invalid");
        }
        let mut cipher = RC4Cipher {
            //zero initialize everything
            i: 0,
            j: 0,
            s: [0; 256],
        };
        for i in 0..256 {
            cipher.s[i] = i as u8;
        }
        let mut j: u8 = 0;
        for i in 0..256 {
            // j += (cipher.s[i] as u8) + key[i % k];
            j = (j.wrapping_add(cipher.s[i] as u8)).wrapping_add(key[i % k]);
            cipher.s.swap(i, j as usize);
        }
        cipher
    }
/// Creates a new RC4 cipher from the input key
Creates a new RC4 cipher from the input key
Creates a new RC4 cipher from the input key
fn new(key: &[u8]) -> RC4Cipher {
        let k = key.len();
        if k < 1 || k > 256 {
            panic!("Key size invalid");
        }
        let mut cipher = RC4Cipher {
            //zero initialize everything
            i: 0,
            j: 0,
            s: [0; 256],
        };
        for i in 0..256 {
            cipher.s[i] = i as u8;
        }
        let mut j: u8 = 0;
        for i in 0..256 {
            // j += (cipher.s[i] as u8) + key[i % k];
            j = (j.wrapping_add(cipher.s[i] as u8)).wrapping_add(key[i % k]);
            cipher.s.swap(i, j as usize);
        }
        cipher
    }
fn new ( key : & [ u8 ] ) -> RC4Cipher { let k = key . len ( ) ; if k < 1 || k > 256 { panic ! ( " " ) ; } let mut cipher = RC4Cipher { //zero initialize everything i : 0 , j : 0 , s : [ 0 ; 256 ] , } ; for i in 0 .. 256 { cipher . s [ i ] = i as u8 ; } let mut j : u8 = 0 ; for i in 0 .. 256 { // j += (cipher.s[i] as u8) + key[i % k]; j = ( j . wrapping_add ( cipher . s [ i ] as u8 ) ) . wrapping_add ( key [ i % k ] ) ; cipher . s . swap ( i , j as usize ) ; } cipher }
Creates a new RC4 cipher from the input key
Creates a new RC4 cipher from the input key
key
&[u8]
key
&[u8]