Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

caesar cipher encryption 1

Status
Not open for further replies.

TheSean

Programmer
Nov 28, 2012
4
0
0
IE
Can anyone help me out with this. I'v to make a Cipher encrypyion in prolog.

Typical input would be AAABBBCCC output would be CCCDDDEEE

it's a 3 letter jump encryption.

Any help is much appreciated.
 
In Prolog, a string is a list of characters codes.
So, if you use SWI Prolog, you can use maplist to add 3 to the codes of the list "AAABBBCCC
 
So, lets say a list
L("AAABBBCCC")
L2("")

I would do for example
encode(Char, L, L2) :- maplist(caesar(Char, L1, L2)

cipher(_, 26, 26) :- !.

would I be right doing this??
 
Here is the code :
Code:
caesar(L1, L2) :-
	maplist(cipher, L1, LT),
	string_to_list(L2,LT).


cipher(X,Y) :-
	Y is X+3.
and what you get
Code:
 ?- caesar("AAABBBCCC", L2) .
L2 = "DDDEEEFFF".
 
Cheers man. Is that the whole program? I thought it would be a bit more complicated than that. This assignment is worth 25% of my total grand for the module.
 
Can anyone help me!!
If I wanted this to work with just the alphabet and no symbols or numbers how do I go about doing this and also is there anyway to use the space tab without getting a symbol in the encrypted part ? Thanks!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top