The issues is that my Vigenere encryption program works to the point where you can encrypt things, and almost decrypt things perfectly. 9/10ths of the time the decryption works but when it decrypts something with over 4 spaces it might cut up the out put. Here is the code and header file.
Header
Main programCode:*I am going to make my own simple encryption program, cause thats what programmers do Name:TothEncrypt Copyright: GNU Public Licence Author:Will Toth Date Started: 29/10/07 14:02 Description: Very Simple Encryption program */ #include <iostream> int TKeyNum=0; class toth { public: void SetNum(int keynum1){TKeyNum=keynum1;}; //Ceasar Shift Cypher. Works 100%. Is very easy to crack void Tencrypt(int key1, char (&array1)[256] ) { int x; int y; for(x=0;array1[x]!='\0';x++) { for(y=0;y<256;y++) { //std::cout << (char)y << std::endl; if(array1[x]==(char)y) // When the charater in the array is equal to the one in the loop { array1[x]=(char)(y+key1); // it adds x (key1) to the current character y=0; break; } } } } void Tdecrypt(int key1, char (&array1)[256] ) { int x; int y; for(x=0;array1[x]!='\0';x++) { for(y=0;y<256;y++) { //std::cout << (char)y << std::endl; if(array1[x]==(char)y) // When the charater in the array is equal to the one in the loop { array1[x]=(char)(y-key1); // it adds x (key1) to the current character y=0; break; } } } } //Vingere Cypher void Tencrypt(char textkey[], char (&array1)[256]) { int x; int y; int z=0; int key1; for(x=0;array1[x]!='\0';x++) //scans whole thing { { if(z==strlen(textkey)) { z=0; } key1=((int)(textkey[z])-'a'); z++; } std::cout << key1 << std::endl; for(y=0;y<256;y++) { //std::cout << (char)y << std::endl; if(array1[x]==(char)y) { array1[x]=(char)(y+key1); y=0; break; } } } } void Tdecrypt(char textkey[], char (&array1)[256]) { int x; int y; int z=0; int key1; for(x=0;array1[x]!='\0';x++) //scans whole thing { { if(z==strlen(textkey)) { z=0; } key1=((int)(textkey[z])-'a'); z++; } std::cout << key1 << std::endl; for(y=0;y<256;y++) { //std::cout << (char)y << std::endl; if(array1[x]==(char)y) { array1[x]=(char)(y-key1); y=0; break; } } } } };
Code://#include <iostream> #include "tothencrypt.h" #include <iostream> int main() { //char dog[4]; toth newtoth; char dog[256] = "the desert fox got foxed"; char keyword[256] = "YouCant gef Daf"; char cat[256] = "Adam Hendrickson Is A crazy Pshyco .........."; /*int i = strlen(keyword); cout << "i = : "<< i << endl; */ //newtoth.Tencrypt(3,cat); newtoth.Tencrypt(keyword,dog); //should be Forltuulod std::cout << "dog :" << dog << "\tShould be: Forltuulod" << std::endl << "Cat :" << cat << "\tShould be: Fdoliruqld" << std::endl; newtoth.Tdecrypt(keyword,dog); std::cout << dog; getchar(); }



LinkBack URL
About LinkBacks


