Welcome to Dream.In.Code
Become a C++ Expert!

Join 149,491 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 1,292 people online right now. Registration is fast and FREE... Join Now!




String Encryption

 
Reply to this topicStart new topic

String Encryption

Juwairia
22 Mar, 2007 - 07:39 PM
Post #1

New D.I.C Head
*

Joined: 22 Mar, 2007
Posts: 2


My Contributions
Hello,

I'm new here, and I need to make a program that uses various encryption methods. I've done the case conversion, writing in reverse order, and eliminating the spaces encryptions.

I'm having problems doing the following:
*Putting the characters in the string into blocks of 2, 3, 4, or any number chosen by the user
*Using a set offset, for example:
with an offset of 3, an A should become a D, a B should become an E, etc. (each character is substituted with the letter 3 alphabets away from it); the 'offset number' is selected by the user
*using a random substitution so that each of the letters used in the string is assigned a random 'equivalent' alphabet that is not repeated, example:
if message is: "this is a cat",
the encryption MAY BE: "ptsj sj k mkp"
(where the random would be: t=p,h=t,i=s,s=j,a=k,c=m)

Can somebody please just 'explain' how to approach the problem, and then i'll try to program it and see how it goes?

Thank you!
Juwairia
User is offlineProfile CardPM
+Quote Post

William_Wilson
RE: String Encryption
23 Mar, 2007 - 04:54 AM
Post #2

lost in compilation
Group Icon

Joined: 23 Dec, 2005
Posts: 4,101



Thanked: 25 times
Dream Kudos: 3275
Expert In: Java, C, Javascript

My Contributions
the easiest way i could see is to cast the chars to ints and get their ascii value, eg: A=65, then add your offset to this and convert back to a char, thus:
offset of 3:
A = 65 + 3 = 68 = D

the captials come first, then the small letters. You may want to run a check that you don't exceed the value 122 as this is small z. There are also the values of some symbols, such as: £Ä you may want to include or not. Just something to consider when writting this.
User is offlineProfile CardPM
+Quote Post

Juwairia
RE: String Encryption
23 Mar, 2007 - 06:15 PM
Post #3

New D.I.C Head
*

Joined: 22 Mar, 2007
Posts: 2


My Contributions
QUOTE(William_Wilson @ 23 Mar, 2007 - 05:54 AM) *

the easiest way i could see is to cast the chars to ints and get their ascii value, eg: A=65, then add your offset to this and convert back to a char, thus:
offset of 3:
A = 65 + 3 = 68 = D

the captials come first, then the small letters. You may want to run a check that you don't exceed the value 122 as this is small z. There are also the values of some symbols, such as: £Ä you may want to include or not. Just something to consider when writting this.



Thank you sooo much!
Also, would you know how to put the characters in the string into blocks of 2, 3, 4, or any number chosen by the user?
Thanks again!
Juwairia

User is offlineProfile CardPM
+Quote Post

Reply to this topicStart new topic
Time is now: 1/7/09 05:36PM

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter

Live C++ Help!

C++ Tutorials

Reference Sheets

C++ Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month