-
-
Save h3ku/16772804adf0bb75a442ca26afb5c504 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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