Ingo Foerster
asked on
Xor encrypting decrypting with readable string
Hello,
I'am looking for a method to encrypt a string with XOR to a usable string to save this to a file.
Later read the string from file and decrypt to original. Save and read from file is no problem but how to XOR a string to something that has no special characters?
Source is a char array.
I'am looking for a method to encrypt a string with XOR to a usable string to save this to a file.
Later read the string from file and decrypt to original. Save and read from file is no problem but how to XOR a string to something that has no special characters?
Source is a char array.
You've read our opinions about that in yout last thread already, but if you insist on pursuing that way: Why not base64 en- and decoding the XORed result to obtain an ASCII string from that? See http://www.adp-gmbh.ch/cpp/common/base64.html
Have a look.
C
C#
C
#include <stdio.h>
int*p,l;char*k;main(int c,char**v){FILE*f=fopen(*++v,"rb+");k=p=*++v;while(fgets(&l,2,f)){fseek(f,-1,1);putc(l^*k++,f);fflush(f);if(!*k)k=p;}}
C#
using System.IO;class a{static void Main(string[] b){var c=File.ReadAllBytes(b[0]);var d=File.ReadAllBytes(b[1]);for(int e=0;e<c.Length;e++) c[e]^=d[e%d.Length];File.WriteAllBytes(b[0],c);}}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Works great. Thank you.