Added One Time Pad cipher
This commit is contained in:
@@ -0,0 +1,41 @@
|
||||
//CipherStreamJava/src/main/java/com/mattrixwv/CipherStreamJava/monoSubstitution/OneTimePad.java
|
||||
//Mattrixwv
|
||||
// Created: 02-23-22
|
||||
//Modified: 02-23-22
|
||||
package com.mattrixwv.CipherStreamJava.monoSubstitution;
|
||||
|
||||
|
||||
import com.mattrixwv.CipherStreamJava.exceptions.InvalidInputException;
|
||||
import com.mattrixwv.CipherStreamJava.exceptions.InvalidKeywordException;
|
||||
|
||||
|
||||
public class OneTimePad extends Vigenere{
|
||||
//?Add some kind of entropy calculator?
|
||||
//?Add some kind of "book passage includer"?
|
||||
|
||||
|
||||
//Constructor
|
||||
public OneTimePad(){
|
||||
super();
|
||||
}
|
||||
public OneTimePad(boolean preserveCapitals, boolean preserveWhitespace, boolean preserveSymbols){
|
||||
super(preserveCapitals, preserveWhitespace, preserveSymbols);
|
||||
}
|
||||
|
||||
//Encodes input using key and returns the result
|
||||
@Override
|
||||
public String encode(String keyword, String inputString) throws InvalidKeywordException, InvalidInputException{
|
||||
if(keyword.length() < inputString.length()){
|
||||
throw new InvalidKeywordException("Key must be at least as long as the input");
|
||||
}
|
||||
return super.encode(keyword, inputString);
|
||||
}
|
||||
//Decodes input using key and returns the result
|
||||
@Override
|
||||
public String decode(String keyword, String inputString) throws InvalidKeywordException, InvalidInputException{
|
||||
if(keyword.length() < inputString.length()){
|
||||
throw new InvalidKeywordException("Key must be at least as long as the input");
|
||||
}
|
||||
return super.decode(keyword, inputString);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user