I save the number to a file, but I need the user not to know it, so I just want to convert it to another encoding. I keep it like this:

[Scr writeToFile:pth atomically:YES encoding:Кодировка error:nil]; 

What specify the encoding so that it translates even a number?

  • Tell me, where did you find the information that in different encodings the numbers have different byte representations? - etki
  • Well, I just need to save the number, but that the user does not know it. - 97mik
  • you can just make a shift before recording and reverse the shift after reading - Alexey Alybin
  • You can simply add some kind of implicit constant, which is stored nearby (it can be a date) or impose xor. - KoVadim
  • You can encrypt, you can in ru.wikipedia.org/wiki/EBCDIC , the question is, why is it necessary? The trivial cipher will still be opened (if desired). So, do not engage in self-deception. - avp

2 answers 2

Do not bother with the encoding, encrypt and all.

Among the simple algorithms you can take the Caesar Cipher . Well, or even come up with a permutation itself, or a binary shift, or just plus / multiply by a constant, and subtract / divide when reading.

    If Src is an instance of NSString and you are worried that your number when opening a file can be seen by everyone, and the goal is just to hide it from the public’s eyes by hiding behind the symbols of the cracks, then write not a string representation of the number but this number. And that is, NSInteger (float, double, short на выбор) -> NSData -> file . Example:

     NSInteger integer = [Scr integerValue]; NSData *data = [NSData dataWithBytes:&integer length:sizeof(integer)]; [data writeToFile:pth atomically:YES]; 

    This will not save from determining the number of more or less IT-literate person, but from the general public will protect. So the problem seems to be solved.

    • And how to read from a file and translate back into a number or string? - 97mik
    • NSInteger integer; NSData * data = [NSData dataWithContentsOfFile: path]; [data getBytes: & integer length: sizeof (integer)]; - szarajewski