Skip to content

Instantly share code, notes, and snippets.

@tychobrailleur
Created March 13, 2022 15:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tychobrailleur/05bced1c59044fcf008fc20c3ad5b5e4 to your computer and use it in GitHub Desktop.
Save tychobrailleur/05bced1c59044fcf008fc20c3ad5b5e4 to your computer and use it in GitHub Desktop.
Shows DES complementation property
-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