Genrating random password

Posted by marian on October 11, 2009

For generating a random password containing hex  digits one can use:

hexdump -n32 -e '"%x"' /dev/random

where 32 is the length of the string, and the format is ‘”%x”.

Substitution cipher

Posted by marian on July 19, 2009

Use case scenario:

  1. Compile the module
  2. 1> c(cipher).
    1. {ok,last}
  3. Use it:
  4. 2> cipher:substitutionCipher(“dan”,[100,97,110],[97,100,110]).
    1. "adn"
  5. Source code:
  6. -module(cipher).
    1. -export([substitutionCipher/3]).
    2.  
    3. makeTranslation([],[],L)->L;
    4. makeTranslation([X|Xs],[Y|Ys],L)->makeTranslation(Xs,Ys,[{X,Y}|L]).
    5. makeTranslation(OriginalAlphabet,CryptedAlphabet)->makeTranslation(OriginalAlphabet,CryptedAlphabet,[]).
    6.  
    7. getTranslation(E,[{X,Y}|Tail])->
    8.  case E==X of
    9.    true -> Y;
    10.    false-> getTranslation(E,Tail)
    11.  end;
    12. getTranslation(_,[])->false.
    13.  
    14. substitute([],_,Substitution)->lists:reverse(Substitution);
    15. substitute([H|RestOfMessage],Translation,Substitution)->
    16. substitute(RestOfMessage,Translation,[getTranslation(H,Translation)]++Substitution).
    17.  
    18. substitutionCipher(Message,OriginalAlphabet,CryptedAlphabet)-> Translation = makeTranslation(OriginalAlphabet,CryptedAlphabet), substitute(Message,Translation,[]).