yazdmich

Crypto

May 3rd, 2013
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.69 KB | None | 0 0
  1. unit
  2. module Crypto
  3. export GetKey, GetKeyInternal, In, Out, key, GenKey, Decoded, Encoded
  4. var ind : int
  5. var key := ""
  6. var encode := ""
  7. var msg : string
  8. var msgout : string
  9. var Encoded := ""
  10. var Decoded := ""
  11. var stream : int
  12. var num : int
  13. var cha : string (1)
  14. var name : string
  15. var alphas := "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz,.?\"'()[]{}1234567890<>;!@#$%^&*`~/\\-=_+ "
  16. var cha1 : array 1 .. 92 of string
  17. var used : array 1 .. 92 of boolean
  18. proc GetKey
  19. put "Please enter the name of the key you are using (key must be in key folder)"
  20. get name
  21. open : stream, "keys/" + name, read
  22. if stream > 0 then
  23. read : stream, key
  24. put "Key: ", key
  25. else
  26. put "Error, key not found, make sure its in the key folder and you spelled it right"
  27. quit
  28. end if
  29. close : stream
  30. end GetKey
  31. proc GetKeyInternal (name1 : string)
  32. open : stream, "keys/" + name1, read
  33. if stream > 0 then
  34. read : stream, key
  35. else
  36. put "Error, key not found, make sure its in the key folder and you spelled it right"
  37. quit
  38. end if
  39. close : stream
  40. end GetKeyInternal
  41. proc In (msg, name : string)
  42. GetKeyInternal (name)
  43. encode := msg
  44. Encoded := ""
  45. for x : 1 .. length (encode)
  46. ind := index (key, encode (x))
  47. if ind > 0 then
  48. Encoded += alphas (ind)
  49. else
  50. Encoded += encode (x)
  51. end if
  52. end for
  53. msgout := ""
  54. end In
  55. proc Out (msg, name : string)
  56. GetKeyInternal (name)
  57. Encoded := msg
  58. Decoded := ""
  59. for x : 1 .. length (Encoded)
  60. ind := index (alphas, Encoded (x))
  61. if ind > 0 then
  62. Decoded += key (ind)
  63. else
  64. Decoded += Encoded (x)
  65. end if
  66. end for
  67. msgout := ""
  68. end Out
  69. proc GenKey
  70. for i : 1 .. 92
  71. used (i) := false
  72. end for
  73. for i : 1 .. 92
  74. cha1 (i) := alphas (i)
  75. end for
  76. for i : 1 .. 92
  77. loop
  78. randint (num, 1, 92)
  79. exit when used (num) = false
  80. end loop
  81. used (num) := true
  82. key += (alphas (num))
  83. end for
  84. put "New key: " ..
  85. put key
  86. put "Please enter a name for this key: " ..
  87. get name
  88. open : stream, "keys/" + name, write
  89. write : stream, key
  90. close : stream
  91. end GenKey
  92. end Crypto
Advertisement
Add Comment
Please, Sign In to add comment