3 Replies - 380 Views - Last Post: 05 April 2012 - 05:47 PM Rate Topic: -----

#1 dman_pl  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 19-March 12

question on encryption in c++

Posted 05 April 2012 - 04:12 PM

Alrighty! So I have taken a c++ class before but I forgot some of it and my books dont help me with what I want to do. I found this code on the internet (I ll post it down below). It does kind of everything I want it to, but I want the code to be easily cracked so someone can actually sit down and in about 10 minutes or so crack it.
Something along the lines of:

original text: My cats stinks
key: Im very hungry

it takes M and the ASCII # and adds it to the ASCII value of I and then encrypts that into 14+9 =25( if those are the ASCII #, cant remember) so that should be Y. That way there is structure to the code and it can be cracked. A friend of mine ( a girl) is currently in a c++ course at my university. And I kind of want to send her this code with of course a different message and tell her how to crack it. Im not going to send her the entire code below so that she does not get the original text ( as that is the point). But I think she would find this somewhat cute and fun so why not :P.

I have this code below which the 26 is because there is that many letters in the alphabet. I know this code is very easy to crack, but that is fine it is supposed to be :) I have a lab that we did last year which used something like I have below. I was pretty sure he sent out the solution in an email, but i cant find it, so I figured Id check here.

offset = (KeyLetter - 'A') + 1
encryptedLetter = 'A' + (original distance from 'A' + offset) % 26
encryptedLetter = 'A' + (originalletter - 'A' + offset) % 26



Using this template:

#include <iostream>
#include <string>
using namespace std;
int main()
{ 
string original = "My cats stinks";
 cout << "Original data = " << original;
 string encrypted = "";
 string unencrypt = "";
 char key = 'x';

 for (int temp = 0; temp < original.size(); temp++){
  encrypted += original[temp] ^ (int(key) + temp) % 255;
 }
 cout << "nEncrypted data = " << encrypted;

 for (int temp = 0; temp < original.size(); temp++){
  unencrypted += encrypted[temp] ^ (int(key) + temp) % 255;
 }
 cout << "nUnencrypted data = " << unencrypt;
}




This post has been edited by ishkabible: 05 April 2012 - 04:45 PM
Reason for edit:: fixed code tags


Is This A Good Question/Topic? 0
  • +

Replies To: question on encryption in c++

#2 DimitriV  Icon User is offline

  • Don't try to save yourself… the circle is complete
  • member icon

Reputation: 544
  • View blog
  • Posts: 2,632
  • Joined: 24-July 11

Re: question on encryption in c++

Posted 05 April 2012 - 04:16 PM

Here's the ASCII codes:
http://www.ascii.cl/
Was This Post Helpful? 0
  • +
  • -

#3 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 5672
  • View blog
  • Posts: 22,524
  • Joined: 23-August 08

Re: question on encryption in c++

Posted 05 April 2012 - 05:43 PM

Your search term would be "Caesar cipher"
Was This Post Helpful? 0
  • +
  • -

#4 dman_pl  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 19-March 12

Re: question on encryption in c++

Posted 05 April 2012 - 05:47 PM

Heh looks like I was a bit off with the ASCII lol

thanks Jack, Ill google that and see if i can come up with anything!
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1