1 // Copyright 2000-2005 the Contributors, as shown in the revision logs.
2 // Licensed under the Apache Public Source License 2.0 ("the License").
3 // You may not use this file except in compliance with the License.
5 package org.ibex.crypto;
9 private final byte[] s = new byte[256];
12 public RC4(byte[] k) {
13 for(int i=0;i<256;i++) s[i] = (byte)i;
14 for(int i=0,j=0;i<256;i++) {
15 j = (j + (s[i]&0xff) + (k[i%k.length]&0xff))&0xff;
22 public void process(byte[] in, int ip, byte[] out, int op, int len) {
26 for(int i=0;i<len;i++) {
28 y = (y + (s[x]&0xff)) & 0xff;
32 int t = ((s[x]&0xff) + (s[y]&0xff))&0xff;
34 out[op+i] = (byte)((in[ip+i]&0xff)^k);