Esempio n. 1
0
        private AffineKey CalculateEncryptKey(Signature signature, int encryptedSignatureByte1, int encryptedSignatureByte2)
        {
            int       deltaSignatureBytes          = -signature.DeltaBytes;                             // Yes, I want minus delta.
            int       deltaEncryptedSygnatureBytes = encryptedSignatureByte1 - encryptedSignatureByte2; // Yes, I want minus delta.
            int       keyA       = Ring.Modulo(deltaEncryptedSygnatureBytes * Ring.Inverse(deltaSignatureBytes, Ring.N), Ring.N);
            int       keyB       = Ring.Modulo(encryptedSignatureByte1 - keyA * signature.Byte1, Ring.N);
            AffineKey encryptKey = new AffineKey(keyA, keyB);

            return(encryptKey);
        }
Esempio n. 2
0
        private AffineKey GetEncryptKey(FileStream inputFileStream, string originalExtension)
        {
            Signature fileSignature = signatures[originalExtension];

            inputFileStream.Position += 1 + originalExtension.Length; // Jump over encrypted extension, where first character means extension length.
            long positionBehindEncryptedExtension = inputFileStream.Position;

            inputFileStream.Position += fileSignature.Byte1Position;
            int encryptedSignatureByte1 = inputFileStream.ReadByte();

            inputFileStream.Position = positionBehindEncryptedExtension + fileSignature.Byte2Position;
            int encyptedSignatureByte2 = inputFileStream.ReadByte();

            inputFileStream.Position = positionBehindEncryptedExtension;

            AffineKey encryptKey = CalculateEncryptKey(fileSignature, encryptedSignatureByte1, encyptedSignatureByte2);

            return(encryptKey);
        }
Esempio n. 3
0
 public async Task DecryptFileAsync(string inputFilePath, string outputFilePath, CancellationToken cancellationToken)
 {
     AffineKey encryptKey = TryGetEncryptKeyByOutputFilePathWithExtension(inputFilePath, outputFilePath);
     await affineCipher.DecryptFileAsync(inputFilePath, outputFilePath, encryptKey, cancellationToken);
 }
Esempio n. 4
0
        public void DecryptFile(string inputFilePath, string outputFilePath) // outputFilePath - with CORRECT extension
        {
            AffineKey encryptKey = TryGetEncryptKeyByOutputFilePathWithExtension(inputFilePath, outputFilePath);

            affineCipher.DecryptFile(inputFilePath, outputFilePath, encryptKey);
        }