Пример #1
0
    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");
        }
    }
Пример #2
0
 public void writeKey(VernamKey vernamKey, String outputPath)
 {
     File.WriteAllBytes(outputPath, vernamKey.getByteArray());
 }
Пример #3
0
 public static BitArray doOperation(BitArray a, VernamKey b)
 {
     a.Xor(b.getKeyBitArray());
     return(a);
 }
Пример #4
0
 public string performTextOperationToString(String text, VernamKey key)
 {
     return(VernamEngine.doOperation(new BitArray(ASCII.GetBytes(text)), key).ToString());
 }
Пример #5
0
 public void performFileStreamOperation(String inputPath, String outputPath, VernamKey vernamKey)
 {
     VernamEngine.doStreamOperation(inputPath, outputPath, vernamKey);
 }
Пример #6
0
 public void fileOperation(String filePath, VernamKey key)
 {
     new BitArrayWriter(VernamEngine.doOperation(new BitArrayReader(filePath).readFileIntoBitSet(), key), filePath).write();
 }
Пример #7
0
 public void performFileOperation(BitArray fileBitSet, VernamKey key, String outputPath)
 {
     new BitArrayWriter(VernamEngine.doOperation(fileBitSet, key), outputPath).write();
 }
Пример #8
0
 static void KeyWriteBackgroundTask(string path, VernamKey vernam)
 {
     new KeyWriter().writeKey(vernam, path);
     MessageBox.Show("Key written", "Confirmation", MessageBoxButtons.OK, MessageBoxIcon.Information);
 }
Пример #9
0
 static void KeyReaderBackgroundTask(string path)
 {
     currentKey = new KeyReader().readKey(path);
     MessageBox.Show("Key read", "Confirmation", MessageBoxButtons.OK, MessageBoxIcon.Information);
 }
Пример #10
0
 static void KeyGen(long size)
 {
     currentKey = new VernamKeyGenerator().generateKey((int)size);
     MessageBox.Show("Key generated", "Confirmation", MessageBoxButtons.OK, MessageBoxIcon.Information);
 }
Пример #11
0
 static void duplicateKeyInMemory(string inputPath, string outputPath, VernamKey vernamKey)
 {
     VernamEngine.doStreamOperation(inputPath, outputPath, vernamKey);
     MessageBox.Show("Operation complete", "Confirmation", MessageBoxButtons.OK, MessageBoxIcon.Information);
 }
Пример #12
0
 static void existingWithKey(string inputPath, VernamKey vernamKey)
 {
     VernamEngine.doStreamOperationNoDuplicate(inputPath, vernamKey);
     MessageBox.Show("Operation complete", "Confirmation", MessageBoxButtons.OK, MessageBoxIcon.Information);
 }