Originally Posted by

**yop**
Output: 2f 7d 76 42 5e bb 85 e4 f2 e7 b0 08 68 bf 0f ce (hex)

Could you elaborate on the "encode result" part? It's obviously not digits.

That's why I've suggested one-time pad, but there are three requirements that the key **must** meet:- it can be used only once,
- it must be of the same length as the message,
- it must be Random(tm).

One-time pad works like this[1]:
for( int i = 0; i < plainText.size(); ++i ) {

cipherText

[i

] = QChar( '0' + (plainText

[i

].

digitValue() + key

[i

].

digitValue() % 10) );

}

QString cipherText( plainText.size(), QChar( 'x' ) );
for( int i = 0; i < plainText.size(); ++i ) {
cipherText[i] = QChar( '0' + (plainText[i].digitValue() + key[i].digitValue() % 10) );
}

*To copy to clipboard, switch view to plain text mode *

The problem is that when somebody has both plainText and cipherText, he can do this:
for( int i = 0; i < plainText.size(); ++i ) {

key

[i

] = QChar( '0' + (cipherText

[i

].

digitValue() - plainText

[i

].

digitValue() % 10) );

}

for( int i = 0; i < plainText.size(); ++i ) {
key[i] = QChar( '0' + (cipherText[i].digitValue() - plainText[i].digitValue() % 10) );
}

*To copy to clipboard, switch view to plain text mode *

That's why it's very important not to reuse the key. In other words, if you will reuse the key --- don't use it.

You can implement one-time pad using a good random generator (in such case the seed would be the real key) and that's what stream ciphers usually do.

You can also consider using RSA with "n" having the same number of digits as the input string, but if those strings have less than few hundred digits it might be easily broken.

[1] Of course it's usually implemented on bit level, so it uses XOR not addition modulo 10.

## Bookmarks