public static void doStreamOperation(String inputPath, String outputPath, VernamKey vernamKey) { BitArray b = vernamKey.getKeyBitArray(); byte[] key = new byte[(b.Length - 1) / 8 + 1]; b.CopyTo(key, 0); string inputFile = Path.GetFullPath(inputPath); if (new FileInfo(inputFile).Length == key.Length) { FileStream fis = new FileStream(inputFile, FileMode.Open, FileAccess.Read); BinaryWriter br = new BinaryWriter(new FileStream(outputPath, FileMode.Create)); int i = 0, j; while ((j = fis.ReadByte()) >= 0) { br.Write((byte)(j ^ key[i])); i++; } fis.Close(); br.Flush(); br.Close(); } else { throw new Exception("Key length mismatch detected"); } }
public void writeKey(VernamKey vernamKey, String outputPath) { File.WriteAllBytes(outputPath, vernamKey.getByteArray()); }
public static BitArray doOperation(BitArray a, VernamKey b) { a.Xor(b.getKeyBitArray()); return(a); }
public string performTextOperationToString(String text, VernamKey key) { return(VernamEngine.doOperation(new BitArray(ASCII.GetBytes(text)), key).ToString()); }
public void performFileStreamOperation(String inputPath, String outputPath, VernamKey vernamKey) { VernamEngine.doStreamOperation(inputPath, outputPath, vernamKey); }
public void fileOperation(String filePath, VernamKey key) { new BitArrayWriter(VernamEngine.doOperation(new BitArrayReader(filePath).readFileIntoBitSet(), key), filePath).write(); }
public void performFileOperation(BitArray fileBitSet, VernamKey key, String outputPath) { new BitArrayWriter(VernamEngine.doOperation(fileBitSet, key), outputPath).write(); }
static void KeyWriteBackgroundTask(string path, VernamKey vernam) { new KeyWriter().writeKey(vernam, path); MessageBox.Show("Key written", "Confirmation", MessageBoxButtons.OK, MessageBoxIcon.Information); }
static void KeyReaderBackgroundTask(string path) { currentKey = new KeyReader().readKey(path); MessageBox.Show("Key read", "Confirmation", MessageBoxButtons.OK, MessageBoxIcon.Information); }
static void KeyGen(long size) { currentKey = new VernamKeyGenerator().generateKey((int)size); MessageBox.Show("Key generated", "Confirmation", MessageBoxButtons.OK, MessageBoxIcon.Information); }
static void duplicateKeyInMemory(string inputPath, string outputPath, VernamKey vernamKey) { VernamEngine.doStreamOperation(inputPath, outputPath, vernamKey); MessageBox.Show("Operation complete", "Confirmation", MessageBoxButtons.OK, MessageBoxIcon.Information); }
static void existingWithKey(string inputPath, VernamKey vernamKey) { VernamEngine.doStreamOperationNoDuplicate(inputPath, vernamKey); MessageBox.Show("Operation complete", "Confirmation", MessageBoxButtons.OK, MessageBoxIcon.Information); }