Skip to content

Instantly share code, notes, and snippets.

@h3ku h3ku/RC4.java Secret
Created Mar 6, 2018

Embed
What would you like to do?
package com.xiaomi.smarthome.library.crypto.rc4coder;
final class RC4 {
private int a;
private int b;
private final byte[] c = new byte[256];
public RC4(byte[] bArr) {
int i;
int length = bArr.length;
for (i = 0; i < 256; i++) {
this.c[i] = (byte) i;
}
i = 0;
for (int i2 = 0; i2 < 256; i2++) {
i = ((i + bArr[i2 % length]) + this.c[i2]) & 255;
byte b = this.c[i2];
this.c[i2] = this.c[i];
this.c[i] = b;
}
this.a = 0;
this.b = 0;
}
public byte a() {
this.a = (this.a + 1) & 255;
this.b = (this.b + this.c[this.a]) & 255;
byte b = this.c[this.a];
this.c[this.a] = this.c[this.b];
this.c[this.b] = b;
return this.c[(this.c[this.a] + this.c[this.b]) & 255];
}
public void a(byte[] bArr) {
for (int i = 0; i < bArr.length; i++) {
bArr[i] = (byte) (bArr[i] ^ a());
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.