RaZgRiZ

CS substitution cypher (simple)

Feb 26th, 2017
293
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.15 KB | None | 0 0
  1. DEFD = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890,./<>?;'[]\:^"{}|`~!@#$%^^&*()_+-= ^t^n" // "
  2. DICT = "96p>.X#^t4/7A0^^5+,sHV<aLFT$E\D[3=]&KvtIzbm)?2q'MrUxQ1R%oecPn^ndyj{~^" }|ON-`;_GZk@CY!JhB*8S(lfuig:wW" // "
  3.  
  4. genrnddict = [
  5.     local tmp dict
  6.     dict = $DEFD
  7.     loop c (strlen $dict) [
  8.         c = (substr $dict (rnd (strlen $dict)) 1)
  9.         dict = (strreplace $dict $c "")
  10.         tmp = (concatword $tmp $c)
  11.     ]
  12.     result $tmp
  13. ]
  14.  
  15.  
  16. encrypt = [
  17.     arg2 = $DICT
  18.     loopconcatword c (strlen $arg1) [ substr $arg2 (strstr $DEFD (substr $arg1 $c 1)) 1 ]
  19. ]
  20.  
  21. decrypt = [
  22.     arg2 = $DICT
  23.     loopconcatword c (strlen $arg1) [ substr $DEFD (strstr $arg2 (substr $arg1 $c 1)) 1 ]
  24. ]
  25.  
  26.  
  27. testcrypto = [
  28.     local output input
  29.     input = (? $numargs $arg1 $DEFD)
  30.     echo (concatword "^f8>>^f7" (escape $input))
  31.     output = (encrypt $input)
  32.     echo (concatword "^f8:::::^f4" (escape $output))
  33.     output = (decrypt $output)
  34.     echo (concatword "^f8<<" (? (=s $input $output) "^f9" "^f3") (escape $output))
  35. ]
  36.  
  37. // Use the commands below for more sophisticated encryption
  38.  
  39.  
  40. encrypt = [
  41.     local offset char out len1 len2 rndp n0 n1 n2 n3 n4 n5 n6 n7 n8 n9
  42.     arg2 = $DICT
  43.     loop i 10 [ [n@i] = (strstr $arg2 $i) ]
  44.     len2 = (strlen $arg2)
  45.     rndp = (& (rnd (pow (+ $n3 (* $n6 $n0)) (max 1 $n9))) 0xFF)
  46.     arg1 = (concatword $arg1 (
  47.         loopconcatword p $rndp [ result " " ]
  48.     ) (tohex $rndp 2))
  49.     len1 = (strlen $arg1)
  50.  
  51.     out = (loopconcatword c $len1 [
  52.         char = (substr $arg1 $c 1)
  53.         offset = (mod (- (+ $offset (* $len1 $n0) (div (* $n1 $n2) $c)) (* $n5 $n6) (div $n7 $n8 $n9)) $len2)
  54.         substr $arg2 ( mod (
  55.             + (strstr $DEFD $char) $offset
  56.         ) $len2 ) 1
  57.     ])
  58.     result $out
  59. ]
  60.  
  61. decrypt = [
  62.     local offset char out len1 len2 n0 n1 n2 n3 n4 n5 n6 n7 n8 n9
  63.     arg2 = $DICT
  64.     len1 = (strlen $arg1)
  65.     len2 = (strlen $arg2)
  66.     loop i 10 [ [n@i] = (strstr $arg2 $i) ]
  67.    
  68.     out = (loopconcatword c $len1 [
  69.         char = (substr $arg1 $c 1)
  70.         offset = (mod (- (+ $offset (* $len1 $n0) (div (* $n1 $n2) $c)) (* $n5 $n6) (div $n7 $n8 $n9)) $len2)
  71.         substr $DEFD ( mod (
  72.             + (- (strstr $arg2 $char) $offset) $len2
  73.         ) $len2 ) 1
  74.     ])
  75.     substr $out 0 (- (strlen $out) (
  76.         substr $out (- (strlen $out) 4) 4
  77.     ) 4)
  78. ]
Advertisement
Add Comment
Please, Sign In to add comment