You are not logged in.

#1 2007-11-27 19:22:08

ramoneur
Member
Registered: 2007-06-04
Posts: 89

C++ simple encryption help

hey im a total newb @ C++ but im making a simple encryption program for a small project of mine.
anyway what i want is, take the text from a variable and encrypt it and then send the encrypted text to a new variable.
i have 2 char arrays holding the letters and respective "encrypted" letter.

looks like this:
char *alfa  = "abcdefghijklmnopqrstyvwxyz";
char *beta = "mqfjhldxgnwersuabkizpyvtco";

(ive also thought about having 2 strings holding the letters if thats easier, like this:
string alfa ("abcdefghijklmnopqrstuvwxyz");
string beta("mqfjhldxgnwersuabkizpyvtco");)

anyway, i have no idea of how to convert the letters in a variable to the respective letters as seen in the *beta variable.

im very happy for any help i can get, and please i know this is neewbish, but im in the beginning of learning C++ (and programming at all tongue)
smile

and im sorry for my english.


A w e s o m e
r
c
h

Offline

#2 2007-11-27 19:33:30

phrakture
Arch Overlord
From: behind you
Registered: 2003-10-29
Posts: 7,879
Website

Re: C++ simple encryption help

Is this school based? Or personal? Is there any reason you cannot just use an existing one-way hash implementation, like md5 or sha1?

Offline

#3 2007-11-27 19:35:49

Cerebral
Forum Fellow
From: Waterloo, ON, CA
Registered: 2005-04-08
Posts: 3,108
Website

Re: C++ simple encryption help

http://www.cplusplus.com/reference/string/
That should have enough information for you to figure out what you need.

Offline

#4 2007-11-27 19:55:04

ramoneur
Member
Registered: 2007-06-04
Posts: 89

Re: C++ simple encryption help

thanks cerebral, ill read through it.
and phrakture: its personal smile


A w e s o m e
r
c
h

Offline

#5 2007-11-27 22:11:18

drakosha
Member
Registered: 2006-01-03
Posts: 253
Website

Re: C++ simple encryption help

beta is basically array with letter to put instead of 'a' in place 0, instead of 'b' in place 1 and so on.
so, beta[ch - 'a'] will give you "encrypted" letter which should be used instead of char ch.

Offline

#6 2007-11-27 23:50:17

Xilon
Member
Registered: 2007-01-01
Posts: 243

Re: C++ simple encryption help

You want a char array, so why use string or char*? Go for char[] wink

Offline

Board footer

Powered by FluxBB