Problem while Writing data into and Reading data ifrom a text file
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
I desperately need some help on this issue I am trying to perform Encryption and Decryption operation using a particular technique. The code is working perfectly. However i
am facing this problem; Once encryption process is performed the encrypted data is written into a file as shown below:
id=fopen('C:\Users\HOME\Desktop\I.txt','w');
fwrite(id,final);
fclose(id);
FINAL is an array of ASCII characters in the range 1 to 256
and this is what i got as an answer for FINAL= xcpucmmucpxcfmc|ppxdpucpxcba
The file I.txt should have contained the same thing but it contained: xcpucmm€ucpxcfmc|ppxdpucpxcba
In the DECRYPTION part i read the file this way:
fid=fopen('C:\Users\HOME\Desktop\I.txt','r');
f=fscanf(dfid,'%c');
fclose(fid);
I proceded by using f (which contains the cipher text) in the decryption process only to get a wrong plaintext.
When i removed all the above codes and simply copied the ciphertext variable FINAL into the variable f in the decryption
process, i got the correct answer i.e
f=final;
My requirement is that both encryption and decryption process must use a text file.
Kindly Help Me !!
0 comentarios
Respuestas (1)
Walter Roberson
el 27 de Abr. de 2012
If you use fwrite() to write the file, you should probably use fread() to read the file.
Question: is "final" an array of characters in the range 1 to 256, or in the range 0 to 255? The 256 would give you problems.
3 comentarios
Ver también
Categorías
Más información sobre Characters and Strings en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!