Created
April 18, 2009 02:28
-
-
Save LBRapid/97397 to your computer and use it in GitHub Desktop.
Simple Mountain Cipher encryption of a plaintext file
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
import java.io.BufferedReader; | |
import java.io.FileReader; | |
import java.io.IOException; | |
public class MountainCipher | |
{ | |
private int numberOfChars; // number of chars in the plaintext | |
private int[] plainText; // array of plain text ASCII codes | |
private int[] cipherText; // array of cipher text ASCII codes | |
private String plainFile; // name of plaintext file | |
private String cipherFile; // name of encrypted file | |
public MountainCipher(String fileName1, String fileName2) throws IOException{ | |
plainFile = fileName1; | |
cipherFile = fileName2; | |
// create new BufferedReader to access the plainText file | |
BufferedReader in = new BufferedReader(new FileReader(plainFile)); | |
numberOfChars = 0; | |
while(in.read() != -1) { // stores number of chars in plainFile in int numberOfChars | |
numberOfChars++; | |
} | |
in.close(); | |
plainText = new int[numberOfChars]; // allocate memory for plainText array | |
cipherText = new int[numberOfChars]; // allocate memory for cipherText array | |
} | |
/** | |
* Read ASCII code of each char in plainFile and store values in plainText[] in pairs | |
*/ | |
public void readPlainText() throws IOException{ | |
// create new BufferedReader to access the plainText file | |
BufferedReader in = new BufferedReader(new FileReader(plainFile)); | |
for(int k = 0; k <= (numberOfChars - 1); k++) { | |
plainText[k] = (int)in.read(); | |
System.out.println(plainText[k]); | |
} | |
in.close(); | |
} | |
/** | |
* Encrypt every pair of ASCII codes in plainText and store in cipherText | |
*/ | |
public void transform() { | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment