Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- unit
- module Crypto
- export GetKey, GetKeyInternal, In, Out, key, GenKey, Decoded, Encoded
- var ind : int
- var key := ""
- var encode := ""
- var msg : string
- var msgout : string
- var Encoded := ""
- var Decoded := ""
- var stream : int
- var num : int
- var cha : string (1)
- var name : string
- var alphas := "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz,.?\"'()[]{}1234567890<>;!@#$%^&*`~/\\-=_+ "
- var cha1 : array 1 .. 92 of string
- var used : array 1 .. 92 of boolean
- proc GetKey
- put "Please enter the name of the key you are using (key must be in key folder)"
- get name
- open : stream, "keys/" + name, read
- if stream > 0 then
- read : stream, key
- put "Key: ", key
- else
- put "Error, key not found, make sure its in the key folder and you spelled it right"
- quit
- end if
- close : stream
- end GetKey
- proc GetKeyInternal (name1 : string)
- open : stream, "keys/" + name1, read
- if stream > 0 then
- read : stream, key
- else
- put "Error, key not found, make sure its in the key folder and you spelled it right"
- quit
- end if
- close : stream
- end GetKeyInternal
- proc In (msg, name : string)
- GetKeyInternal (name)
- encode := msg
- Encoded := ""
- for x : 1 .. length (encode)
- ind := index (key, encode (x))
- if ind > 0 then
- Encoded += alphas (ind)
- else
- Encoded += encode (x)
- end if
- end for
- msgout := ""
- end In
- proc Out (msg, name : string)
- GetKeyInternal (name)
- Encoded := msg
- Decoded := ""
- for x : 1 .. length (Encoded)
- ind := index (alphas, Encoded (x))
- if ind > 0 then
- Decoded += key (ind)
- else
- Decoded += Encoded (x)
- end if
- end for
- msgout := ""
- end Out
- proc GenKey
- for i : 1 .. 92
- used (i) := false
- end for
- for i : 1 .. 92
- cha1 (i) := alphas (i)
- end for
- for i : 1 .. 92
- loop
- randint (num, 1, 92)
- exit when used (num) = false
- end loop
- used (num) := true
- key += (alphas (num))
- end for
- put "New key: " ..
- put key
- put "Please enter a name for this key: " ..
- get name
- open : stream, "keys/" + name, write
- write : stream, key
- close : stream
- end GenKey
- end Crypto
Advertisement
Add Comment
Please, Sign In to add comment