![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Professional Programmer
Join Date: Sep 2005
Location: serbia & montenegro
Posts: 484
Rep Power: 3
![]() |
Text encryption in C
I was very bored in school so i made a sort of xor encryption in c.
Here is the source code: #include <stdio.h>
#include <stdlib.h>
int main(int argc, char *argv[])
{
char fileName[30];
int temp;
FILE *fp;
FILE *fp1;
printf( "Text Encoder 1.0 \n\n" );
printf( "Enter the file name you want to encrypt/decrypt: \n" );
printf( "The file must be in the same folder as the program. \n" );
printf( "The lenght of the file name may not contain spaces nor more then 30 chars. \n" );
scanf( "%s", &fileName );
if((fp = fopen( fileName, "r" )) == NULL)
{
printf( "That file doesn't exist!!! \n\n" );
system( "PAUSE" );
return 0;
}
fp1 = fopen( "TE_file.txt", "w" );
printf( "Processing.... please wait \n" );
while( temp != -1 )
{
temp = fgetc( fp );
if( temp == -1 ) break;
temp = temp ^ 1926701;
fputc( temp, fp1 );
}
printf( "Done. \n \n" );
system("PAUSE");
return 0;
} |
|
|
|
|
|
#2 | |
|
Expert Programmer
Join Date: Aug 2005
Location: Rotterdam, the Netherlands
Posts: 942
Rep Power: 4
![]() |
Quote:
fgets(fileName, 30, stdin); |
|
|
|
|
|
|
#3 |
|
Professional Programmer
Join Date: Sep 2005
Location: serbia & montenegro
Posts: 484
Rep Power: 3
![]() |
I know, it is my first prog in c, after 1 hour of reading the c documentation.
I want to learn c so I am happy that it works. The experience will come later. |
|
|
|
|
|
#4 | |
|
Hobbyist Programmer
Join Date: Aug 2005
Location: Hiding from... them...
Posts: 110
Rep Power: 4
![]() |
Quote:
|
|
|
|
|
|
|
#5 |
|
Programming Guru
![]() ![]() ![]() |
cool. here is my XOR function in C#...
If you want to, feel free to convert it to C/C++ ... static string MyXOR (string data)
{
string key = "test";
string retValue = "";
int i = 0;
int x = 0;
int[] cipher = new int[data.Length];
x = 0;
for (i = 0; i < data.Length; i++)
{
//Console.Write((char)((data[i] ^ key[x])));
retValue = retValue + (char)((data[i] ^ key[x]));
cipher[i] = (data[i] ^ key[x]);
x++;
if (x >= key.Length)
x = 0;
}
return retValue;
}EDIT: These code tags hammers my identations all of the time ![]()
__________________
http://jasonpowers.net "There are a thousand hacking at the branches of evil to one who is striking at the root." |
|
|
|
|
|
#6 |
|
Resident Grouch
![]() ![]() ![]() ![]() ![]() ![]() Join Date: Jun 2005
Posts: 6,453
Rep Power: 10
![]() |
I have problems with it too, IR. Your source editor MUST have the ability to replace the tabs with the appropriate number of spaces before you copy and paste. Unilaterally taking that step "as you work" tends to screw up auto-indenting, so the visible page often isn't suitable.
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code. Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers |
|
|
|
|
|
#7 |
|
Programming Guru
![]() ![]() ![]() |
Hmmm, seems like I could toggle that feature some where in the IDE options. I'll look into it. Thanks for the info
__________________
http://jasonpowers.net "There are a thousand hacking at the branches of evil to one who is striking at the root." |
|
|
|
|
|
#8 | |
|
Professional Programmer
Join Date: Sep 2005
Location: serbia & montenegro
Posts: 484
Rep Power: 3
![]() |
Quote:
|
|
|
|
|
|
|
#9 |
|
Resident Grouch
![]() ![]() ![]() ![]() ![]() ![]() Join Date: Jun 2005
Posts: 6,453
Rep Power: 10
![]() |
I would be interested in hearing you reassess your own statement in a mere five years.
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code. Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers |
|
|
|
|
|
#10 |
|
Professional Programmer
Join Date: Sep 2005
Location: serbia & montenegro
Posts: 484
Rep Power: 3
![]() |
What are you trying to say?
Well, maybe i am not a guru like you DaWei , but I am neither a very very beginner... |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|