-2

I am trying to create a simple encryptation scheme for strings. Each character of the string is given another ascii value.

It entails writing ascii characters upto 246 to a simple file on disk.

I want to find out if it is safe to write these special characters to the disk or can it cause untoward results. Thanks for your help.

Edit: I am considering algorithm similar to following:

* Convert each character of string to its integer number (hence 110 for 'n' and 122 for 'z')
* Double that number (get 220 and 244)
* Convert this to character (will get extended ascii codes)
* Save these characters to file. 

Is it safe to save these extended ascii characters to disk files using usual text file writing functions?

rnso
  • 23,686
  • 25
  • 112
  • 234

1 Answers1

0

There is only a limited set of ASCII characters. There are 95 printable characters such as 'A' but also the space character. There are 33 printable characters such as Line Feed, Carriage Return, NUL but also DELETE. So you cannot use 246 characters of ASCII as there are only 128 total available. ASCII is strictly 7 bits giving you 2^7 = 128 possible values.

Even if you would use the ISO 8859 Latin character set or the Windows-1252 character set you would still have the unprintable control characters to deal with, leaving you with 256 - 33 - 5 characters or 218 characters. Windows-1252 still has 5 undefined characters.

What you can do is of course save your data as bytes. Each byte has 256 possible values (usually 0 to 255 or -128 to 127). As long as you open files as binary this pose no problem.


You can of course store as many characters in a file as you want, up to the file system or operating system limit. So I presume you didn't ask that.

Maarten Bodewes
  • 90,524
  • 13
  • 150
  • 263
  • I don't see any reason to change my answer. Read/write encrypted bytes, decrypt into characters and show those. That way you don't need to get into all this nitty-gritty about character sets, which is more complex to understand than it is to crack your encryption code. – Maarten Bodewes Jun 19 '17 at 11:16