⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 rc4engine.java

📁 java 文件下载器。可自定义
💻 JAVA
字号:
// Decompiled by Jad v1.5.8e2. Copyright 2001 Pavel Kouznetsov.
// Jad home page: http://kpdus.tripod.com/jad.html
// Decompiler options: packimports(3) fieldsfirst ansi space 
// Source File Name:   RC4Engine.java

package org.bouncycastle.crypto.engines;

import org.bouncycastle.crypto.CipherParameters;
import org.bouncycastle.crypto.StreamCipher;
import org.bouncycastle.crypto.params.KeyParameter;

public class RC4Engine
	implements StreamCipher
{

	private static final int STATE_LENGTH = 256;
	private byte engineState[];
	private int x;
	private int y;
	private byte workingKey[];

	public RC4Engine()
	{
		engineState = null;
		x = 0;
		y = 0;
		workingKey = null;
	}

	public void init(boolean forEncryption, CipherParameters params)
	{
		if (params instanceof KeyParameter)
		{
			workingKey = ((KeyParameter)params).getKey();
			setKey(workingKey);
			return;
		} else
		{
			throw new IllegalArgumentException((new StringBuilder()).append("invalid parameter passed to RC4 init - ").append(params.getClass().getName()).toString());
		}
	}

	public String getAlgorithmName()
	{
		return "RC4";
	}

	public byte returnByte(byte in)
	{
		x = x + 1 & 0xff;
		y = engineState[x] + y & 0xff;
		byte tmp = engineState[x];
		engineState[x] = engineState[y];
		engineState[y] = tmp;
		return (byte)(in ^ engineState[engineState[x] + engineState[y] & 0xff]);
	}

	public void processBytes(byte in[], int inOff, int len, byte out[], int outOff)
	{
		for (int i = 0; i < len; i++)
		{
			x = x + 1 & 0xff;
			y = engineState[x] + y & 0xff;
			byte tmp = engineState[x];
			engineState[x] = engineState[y];
			engineState[y] = tmp;
			out[i + outOff] = (byte)(in[i + inOff] ^ engineState[engineState[x] + engineState[y] & 0xff]);
		}

	}

	public void reset()
	{
		setKey(workingKey);
	}

	private void setKey(byte keyBytes[])
	{
		workingKey = keyBytes;
		x = 0;
		y = 0;
		if (engineState == null)
			engineState = new byte[256];
		for (int i = 0; i < 256; i++)
			engineState[i] = (byte)i;

		int i1 = 0;
		int i2 = 0;
		for (int i = 0; i < 256; i++)
		{
			i2 = (keyBytes[i1] & 0xff) + engineState[i] + i2 & 0xff;
			byte tmp = engineState[i];
			engineState[i] = engineState[i2];
			engineState[i2] = tmp;
			i1 = (i1 + 1) % keyBytes.length;
		}

	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -