Are there any tutorials on how to encrypt files in C++
And if so...can some one give me a link. Thanks
-Nick
Are there any tutorials on how to encrypt files in C++
And if so...can some one give me a link. Thanks
-Nick
Have ur data inputted as an array of characters. From there, use a for loop to go through each letter and use a function inside the loop to encrypt it. The same goes for decoding but with the opposite of the encoding function.
Dont know any tuts, but Applied Cryptography by Bruce Schnider is a good book and has examples in C.......
You might get it at your local library....whaich is where I found it originally....
thanks for the replys already...what would help is if some one could please insert like a sample code so i can try it and see how it works...Thanks in advance
Funny thing about Applied Chryptography.... I heard the recent edition was to include source code, but but the NSA blocked it..... You can get the disk for $40 (I think) in the USA only......
There are copies floating around the web though
Free book online:
http://www.cacr.math.uwaterloo.ca/hac/
This code will encrypt .txt files. Was written on a dos compiler so u might have a few problems in windows.
#include<string.h>
#include<stdio.h>
#include<fstream.h>
#include<conio.h>
int main()
{
clrscr();
int choice,num;
char ifname[20],ofname[20],Key[20],ch;
cout<<"\t\t\t*-------------------*\n"<<"\t\t\t| 1) Encode. |\n"<<"\t\t\t| 2) Decode. |\n"<<"\t\t\t| 3) Exit. |\n"<<"\t\t\t*-------------------*\n";
cout<<"\nEnter your choice: ";
cin>>choice;
if(choice==3){clrscr();
cout<<"This program was written by Shahab Faruqi.\n\n";
cout<<"It is distributed under the GNU General Public License\n";
cout<<"For more information write to the Free Software Foundation\n";
cout<<"Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307.\n";
cout<<"\nThank you!!";
return 0;}
clrscr();
cout<<"Enter input filename : ";gets(ifname);fflush(stdin);cout<<"\n";
int i;
cout<<"Enter output filename: ";gets(ofname);fflush(stdin);cout<<"\n";
ifstream infile;
ofstream outfile;
infile.open(ifname);
outfile.open(ofname);
switch(choice)
{
case 1:cout<<"Enter key: ";gets(Key);fflush(stdin);
num=strlen(Key);
while(infile)
{
i=0;
while((i<num)&&(infile)){
infile.get(ch);if(!infile){cout<<"\nThe file was successfully encrypted.";getch();goto end;}
ch=char(char(ch)+char(Key[i]));//add ASCII values of key
outfile.put(ch);//characters in the file & copy to new file
i++;
}
//inner while
}//outer while
break;
case 2:cout<<"Enter key: ";gets(Key);fflush(stdin);
num=strlen(Key);
while(infile)
{
i=0;
while((i<num)&&(infile)){
infile.get(ch);if(!infile){cout<<"\nThe file was successfully decrypted.";getch();goto end;}
ch=char(char(ch)-char(Key[i]));//subtract ASCII values of key
outfile.put(ch);//characters in the file & copy to new file
i++;
}
//inner while
}//outer while
break;
}//end switch
end:
infile.close();
outfile.close();
return 0;
}
I remember in calulus class that you can use a matrix to multilply the ascii value of each letter and encript it that way. Using a matrix is harder to decifer if someone else gets your message. Although I do not remember how to do this (been 6 years), but I do think I will get into this before too long.
C++ Is Powerful
I use C++
There fore I am Powerful
Can you guys give an in-program decrypt / encrypt source code? That way when you need a file you decrypt it, read it, then encrypt it again? I know I can pick apart that dudes code, but I am lazy
/* RC4 Stream Cipher algorithm designed by RSA Inc.
Written by Graham Richter ([email protected])
*/
#include <stdio.h>
#include <iostream.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
unsigned char S[256],K[256];
char Key[]="123456789";
unsigned char data,tmp,t,i,j=0;
void prepkey(void)
{
for (int z=0;z<256;z++) {
S[z]=z;
K[z]=Key[z%strlen(Key)];
}
for (int z=0;z<256;z++) {
j=j+S[z]+K[z];
tmp=S[z];
S[z]=S[j];
S[j]=tmp;
}
j=0;
}
unsigned char RC4(void)
{
i=i+1;
j=j+S[i];
tmp=S[i];
S[i]=S[j];
S[j]=tmp;
t=S[i]+S[j];
return(S[t]);
}
void main(void){
prepkey();
/* Each call to RC4() returns the next keystream byte. Data is encrypted by XORing the data byte with the next keystream byte.*/
// encrypted_data = plain_data ^ RC4();
}