Java - RSA Implementation |
||
![]() ![]() Lt CyberTNT No javadoc comments / junit tests yet. package net.cyberarmy.sneak.algorithm;
import java.beans.IntrospectionException;
import java.beans.PropertyDescriptor;
import java.math.BigInteger;
/**
*
*
* @author Cybertnt
* @since 21.03.2005
*/
public class RSA extends Cipher implements DataDependentAlgorithm {
private BigInteger publicKey;
private BigInteger privateKey;
private BigInteger moduloKey;
private String execute(String input, BigInteger key) {
String[] splitInput = input.split(" ");
StringBuffer result = new StringBuffer();
for (int i = 0; i < splitInput.length; i++) {
result.append(execute(BigInteger.valueOf(Long.parseLong(
splitInput[i])), key, moduloKey));
result.append(' ');
}
return result.toString().trim();
}
private BigInteger execute(BigInteger input, BigInteger key,
BigInteger moduloKey) {
return input.modPow(key, moduloKey);
}
public String execute(String input) {
return execute(input, publicKey);
}
public String reverse(String input) {
return execute(input, privateKey);
}
public PropertyDescriptor[] getRequiredProperties() {
try {
return new PropertyDescriptor[] {
new PropertyDescriptor("publicKey", RSA.class),
new PropertyDescriptor("privateKey", RSA.class),
new PropertyDescriptor("moduloKey", RSA.class)
};
} catch (IntrospectionException exc) {
exc.printStackTrace();
}
return null;
}
/**
* @return Returns the publicKey.
*/
public long getPublicKey() {
return publicKey.longValue();
}
/**
* @param publicKey The publicKey to set.
*/
public void setPublicKey(long publicKey) {
this.publicKey = BigInteger.valueOf(publicKey);
}
/**
* @return Returns the privateKey.
*/
public long getPrivateKey() {
return privateKey.longValue();
}
/**
* @param privateKey The privateKey to set.
*/
public void setPrivateKey(long privateKey) {
this.privateKey = BigInteger.valueOf(privateKey);
}
/**
* @return Returns the moduloKey.
*/
public long getModuloKey() {
return moduloKey.longValue();
}
/**
* @param moduloKey The moduloKey to set.
*/
public void setModuloKey(long moduloKey) {
this.moduloKey = BigInteger.valueOf(moduloKey);
}
}
>+++++[<++++>-]<++[>+++>++++<<-]>+.>+.< -.<+++[>+>--<<-]>.>-.>++[<+<++++>>-]<.<+.>. Replies:
|
||
| CyberArmy::Forum v0.6 Generated In 0.02396 seconds |