Created
March 13, 2022 15:48
-
-
Save tychobrailleur/05bced1c59044fcf008fc20c3ad5b5e4 to your computer and use it in GitHub Desktop.
Shows DES complementation property
This file contains hidden or 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
-module(mydes). | |
-export([test/0, complement/1]). | |
complement(<<>>) -> | |
<<>>; | |
complement(<<1:1, Rest/bitstring>>) -> | |
Complement = complement(Rest), | |
<<0:1, Complement/bitstring>>; | |
complement(<<0:1, Rest/bitstring>>) -> | |
Complement = complement(Rest), | |
<<1:1, Complement/bitstring>>. | |
encrypt(Msg, Key) -> | |
crypto:crypto_one_time(des_ecb, Key, Msg, true). | |
test() -> | |
Message = <<"Some Message">>, | |
Key = crypto:strong_rand_bytes(8), | |
io:format("Cipher: ~p.~n", [complement(encrypt(Message, Key))]), | |
io:format("Complement: ~p.~n", [encrypt(complement(Message), complement(Key))]). |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment