|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcz.cuni.jagrlib.obscure.Enigma
public class Enigma
Text file scrambling algorithm. Preserves original line splitting, so VCS systems won't get overburdened. Able to skip over initial Javadoc comment.
In honour of Bletchley Park codebreakers..
Field Summary | |
---|---|
protected int |
CHAR_MASK
|
protected long |
INIT_SEED
|
protected int[] |
inv
Inverted "perm". |
protected String |
key
Universal key = arbitrary string (only low-order bits of UNICODE are used). |
protected int |
MUL1
|
protected int[] |
perm
Pseudo-random permutation used for seed iteration. |
protected int |
PRIME1
|
protected long |
seed
Encryption/decryption seed. |
protected int |
SUM0
|
protected static String |
table6
Random permutation of "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ-+". |
Constructor Summary | |
---|---|
Enigma()
Have to enter encryption key later ( setKey(java.lang.String) ). |
|
Enigma(String k)
Should enter encryption key here or call setKey(java.lang.String) later. |
Method Summary | |
---|---|
protected void |
advance(int val)
Advances the seed over one 16-bit integer value. |
protected void |
advanceLine(String line)
Advances the seed over the line of text. |
protected void |
buildPermutation(int prime1,
int mul1,
int[] forward,
int[] inverse)
Builds key-based (scrambled) permutation of integers [ 0, forward.length - 1 ] . |
protected char |
decode(int code)
Decodes one 18-bit code number into 16-bit character, advances the seed.. |
protected static int |
decode18(String line,
int i)
|
protected static int |
decode6(char c)
|
int |
decodeFile(String inFileName,
String outFileName)
Decodes the whole text file. |
int |
decodeJavaSource(String inFileName,
String outFileName)
Encodes Java source file with leading Javadoc comment. |
String |
decodeLine(String[] prefix,
int gap,
String code)
Decrypt one line of text. |
protected int |
encode(char ch)
Encodes one 16-bit character, returns result in 18 bits, advances the seed.. |
protected static void |
encode18(StringBuffer buf,
int value)
|
protected static char |
encode6(int val)
|
int |
encodeFile(String inFileName,
String outFileName)
Encodes the whole text file. |
int |
encodeJavaSource(String inFileName,
String outFileName)
Encodes Java source file with leading Javadoc comment. |
String |
encodeLine(String[] prefix,
int gap,
String line)
Encrypt one line of text. |
protected void |
init()
Initializes the encoding/decoding sequence. |
static void |
main(String[] args)
Command-line encryptin/decrypting utility. |
void |
setKey(String k)
Empty keys are replaced by default (11-letter) key. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
protected final int PRIME1
protected final int MUL1
protected final int CHAR_MASK
protected final long INIT_SEED
protected final int SUM0
protected String key
protected int[] perm
protected int[] inv
protected long seed
protected static final String table6
Constructor Detail |
---|
public Enigma()
setKey(java.lang.String)
).
public Enigma(String k)
setKey(java.lang.String)
later.
Method Detail |
---|
public void setKey(String k)
protected void buildPermutation(int prime1, int mul1, int[] forward, int[] inverse)
[ 0, forward.length - 1 ]
.
protected void init()
protected int encode(char ch)
protected void advance(int val)
protected char decode(int code)
protected void advanceLine(String line)
protected static final char encode6(int val)
protected static final int decode6(char c)
protected static final void encode18(StringBuffer buf, int value)
protected static final int decode18(String line, int i)
public String encodeLine(String[] prefix, int gap, String line)
public String decodeLine(String[] prefix, int gap, String code)
public int encodeFile(String inFileName, String outFileName) throws IOException
IOException
FileNotFoundException
public int decodeFile(String inFileName, String outFileName) throws IOException
IOException
FileNotFoundException
public int encodeJavaSource(String inFileName, String outFileName) throws IOException
IOException
FileNotFoundException
public int decodeJavaSource(String inFileName, String outFileName) throws IOException
IOException
FileNotFoundException
public static void main(String[] args)
Usage: Enigma {-e|-d|-je|-jd} [-k <key>] <in-file> <out-file>
Must enter one of commands: -e, -d, -je, -jd. Also the "-k" (key) parameter is higly recommended.
-e: regular text-file encryption.
-d: regular text-file decryption (inverse to "-e").
-je: Java source file encryption.
-jd: Java source file decryption (inverse to "-je").
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |