Advertisement
avejidah

Cryptoanalysis solver

Mar 4th, 2013
402
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.    4.  Here's a cryptarithmetic problem published in 1933 in a journal
  2.       called "Sphinx":
  3.  
  4.           S E P T E M B R E
  5.         - E R B M E T P E S
  6.         -------------------
  7.           M P P B R P S S M
  8.  
  9.        Use generate-and-test.  An appropriate query would be of the form:
  10.  
  11.         ?- crypto(S,E,P,T,M,B,R).
  12.  
  13.        which would return assignments for S,E,P,etc that make the math correct.
  14.  
  15.        Make sure you never let S=E, or P=T, etc... all of the
  16.        distinct letters have to stand for distinct digits.
  17.  
  18.        It might run slowly!
  19.  
  20.  
  21. crypto(S,E,P,T,M,B,R) :-
  22.  % Every letter must be a valid digit.
  23.  digit(S), digit(E), digit(P), digit(T), digit(M), digit(B), digit(R),
  24.  % No digit can equal any other digit.
  25.  S \= E, S \= P, S \= T, S \= M, S \= B, S \= R,
  26.          E \= P, E \= T, E \= M, E \= B, E \= R,
  27.                  P \= T, P \= M, P \= B, P \= R,
  28.                          T \= M, T \= B, T \= R,
  29.                                  M \= B, M \= R,
  30.                                          B \= R,
  31.  Minuend    is S*10^8 + E*10^7 + P*10^6 + T*10^5 + E*10^4 + M*10^3 + B*10^2 + R*10 + E,
  32.  Subtrahend is E*10^8 + R*10^7 + B*10^6 + M*10^5 + E*10^4 + T*10^3 + P*10^2 + E*10 + S,
  33.  Difference is Minuend - Subtrahend,
  34.  Expected   is M*10^8 + P*10^7 + P*10^6 + B*10^5 + R*10^4 + P*10^3 + S*10^2 + S*10 + M,
  35.  Difference = Expected.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement