1
How to write a cryptographic game program in c language?
Write a module which encodes as well as decodes messages regulating any user-supplied code. The formula is to be review from a content record to set up encoder/ decoder array. Add spaces as well as usual punctuation characters in a code.The user is since a menu or choices to encode, decode, or come in a brand new formula from a keyboard. How do we do it?
Obviously your homework. The general idea is that YOU do it to reinforce the concepts covered in class. Expecting others to do it for you means you will never learn to think for yourself.
From the sounds of it this is a straightforward substitution cypher system, each character is replaced by another, it offers a minimal amount of security.
The following is rather verbose pseudo code, it could be simplified, i.e. use a single encode decode function, but is for readability.
You could also expand the concept to allow the plainText to be extended via the update routine.
PSEUDO CODE
declare PlainText as character array size (NUMBER OF SUPPORTED CHARACTERS)
declare EncryptionKey as character array size (NUMBER OF SUPPORTED CHARACTERS)
declare Text as string
declare Flag as boolean value True
declare EncryptionKeyValid as boolean value False
EncryptionKeyValid = read Encryption Key from File
LOOP WHILE ( Flag )
..IF ( EncryptionKeyValid ) THEN
….Show Menu
….get UserSelection
..ELSE
….UserSelection = Enter New Encryption Key
..END IF
..IF ( Encode Message Selected ) THEN
….output Enter Message to be Encoded
….get Text
….Encode Text using EncryptionKey
..ELSE IF ( Decode Message Selected ) THEN
….output Enter Message to be Decoded
….get Text
….Decode Text using EncryptionKey
..ELSE IF ( Enter New Encryption Key Selected ) THEN
….output Enter New Encryption Key for the following characters
….output PlainText
….get Text
….IF ( Validate Encryption Key(Text) ) THEN
……EncryptionKeyValid = True
……EncryptionKey =Text
……Save EncryptionKey to File
……output Encryption Key Updated.
….ELSE
……output ERROR : Encryption Key entered failed validation. Old Key retained.
….END IF
..ELSE IF ( Exit selected ) THEN
….clear Flag
..END IF
END LOOP
Encode
..declare valid as boolean value True
..LOOP FOR EACH character in inputText
….index = Find(character in PlainText)
….IF ( index is valid ) THEN
……output character from EncryptionKey (element index)
….ELSE
……output ERROR – Invalid/unsupported character "(character)" in input string
……valid = False
….END IF
..END LOOP
END Encode (return valid)
Decode
..declare valid as boolean value True
..LOOP FOR EACH character in inputText
….index = Find(character in EncryptionKey )
….IF ( index is valid ) THEN
……output character from PlainText(element index)
….ELSE
……output ERROR – Invalid/unsupported character "(character)" in input string
……valid = False
….END IF
..END LOOP
END Decode (return valid)
Validate Encryption Key
..declare valid as boolean value True
..IF ( Length of inputText matches (NUMBER OF SUPPORTED CHARACTERS) ) THEN
….LOOP FOR (NUMBER OF SUPPORTED CHARACTERS)
……count occurances of character in inputText
……IF ( count is greater than 1) THEN
……..valid = False
……END IF
….END LOOP
..ELSE
….valid = False
..END IF
END Validate Encryption Key (return valid)
Was this answer helpful?
LikeDislike