https://wiki.qt.io/index.php?title=SimpleCrypt_algorithm_details&feed=atom&action=historySimpleCrypt algorithm details - Revision history2024-03-29T10:32:03ZRevision history for this page on the wikiMediaWiki 1.39.4https://wiki.qt.io/index.php?title=SimpleCrypt_algorithm_details&diff=19722&oldid=prevWaldyrious: convert {{doclinkref}} to the improved {{doclink}}2015-10-21T12:30:47Z<p>convert {{doclinkref}} to the improved {{doclink}}</p>
<table style="background-color: #fff; color: #202122;" data-mw="interface">
<col class="diff-marker" />
<col class="diff-content" />
<col class="diff-marker" />
<col class="diff-content" />
<tr class="diff-title" lang="en">
<td colspan="2" style="background-color: #fff; color: #202122; text-align: center;">← Older revision</td>
<td colspan="2" style="background-color: #fff; color: #202122; text-align: center;">Revision as of 12:30, 21 October 2015</td>
</tr><tr><td colspan="2" class="diff-lineno" id="mw-diff-left-l173">Line 173:</td>
<td colspan="2" class="diff-lineno">Line 173:</td></tr>
<tr><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><br/></td><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><br/></td></tr>
<tr><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>=== Compression ===</div></td><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>=== Compression ===</div></td></tr>
<tr><td class="diff-marker" data-marker="−"></td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div>If the Compression flag is set, the data in the examples above is compressed using {{<del style="font-weight: bold; text-decoration: none;">DocLinkRef</del>|<del style="font-weight: bold; text-decoration: none;">ref=</del>QByteArray|<del style="font-weight: bold; text-decoration: none;">anchor=</del>qCompress|<del style="font-weight: bold; text-decoration: none;">label=</del>QByteArray::qCompress()}}. The used compression level is 9 (maximum). On decryption, the data must then be uncompressed using {{<del style="font-weight: bold; text-decoration: none;">DocLinkRef</del>|<del style="font-weight: bold; text-decoration: none;">ref=</del>QByteArray|<del style="font-weight: bold; text-decoration: none;">anchor=</del>qUncompress|<del style="font-weight: bold; text-decoration: none;">label=</del>QByteArray::qUncompress()}}.</div></td><td class="diff-marker" data-marker="+"></td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div>If the Compression flag is set, the data in the examples above is compressed using {{<ins style="font-weight: bold; text-decoration: none;">DocLink</ins>|QByteArray|qCompress|QByteArray::qCompress()}}. The used compression level is 9 (maximum). On decryption, the data must then be uncompressed using {{<ins style="font-weight: bold; text-decoration: none;">DocLink</ins>|QByteArray|qUncompress|QByteArray::qUncompress()}}.</div></td></tr>
<tr><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><br/></td><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><br/></td></tr>
<tr><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>=== Result ===</div></td><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>=== Result ===</div></td></tr>
<tr><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>The resulting binary plaintext is the data retreived from the decrypted payload or, if used, by the (de) compression step above.</div></td><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>The resulting binary plaintext is the data retreived from the decrypted payload or, if used, by the (de) compression step above.</div></td></tr>
<!-- diff cache key heroku_app_db:diff::1.12:old-18005:rev-19722 -->
</table>Waldyrioushttps://wiki.qt.io/index.php?title=SimpleCrypt_algorithm_details&diff=18005&oldid=prevNetZwerg: Removed double heading2015-06-16T10:10:21Z<p>Removed double heading</p>
<table style="background-color: #fff; color: #202122;" data-mw="interface">
<col class="diff-marker" />
<col class="diff-content" />
<col class="diff-marker" />
<col class="diff-content" />
<tr class="diff-title" lang="en">
<td colspan="2" style="background-color: #fff; color: #202122; text-align: center;">← Older revision</td>
<td colspan="2" style="background-color: #fff; color: #202122; text-align: center;">Revision as of 10:10, 16 June 2015</td>
</tr><tr><td colspan="2" class="diff-lineno" id="mw-diff-left-l1">Line 1:</td>
<td colspan="2" class="diff-lineno">Line 1:</td></tr>
<tr><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>[[Category:Snippets]]</div></td><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>[[Category:Snippets]]</div></td></tr>
<tr><td class="diff-marker" data-marker="−"></td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div><del style="font-weight: bold; text-decoration: none;">= SimpleCrypt algorithm and format =</del></div></td><td colspan="2" class="diff-side-added"></td></tr>
<tr><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>This page explains in more detail the format used by the [[Simple_encryption]] code. The encryption and decryption code works from a {{DocLink|QByteArray}} to a '''QByteArray'''. The options to use {{DocLink|QString}} are just provided for convenience. The first two sections detail how the stings and byte arrays correspond for both the plaintext and the cyphertexts. Then, the format of the binary '''QByteArray''' cyphertext is detailed.</div></td><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>This page explains in more detail the format used by the [[Simple_encryption]] code. The encryption and decryption code works from a {{DocLink|QByteArray}} to a '''QByteArray'''. The options to use {{DocLink|QString}} are just provided for convenience. The first two sections detail how the stings and byte arrays correspond for both the plaintext and the cyphertexts. Then, the format of the binary '''QByteArray''' cyphertext is detailed.</div></td></tr>
<tr><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><br/></td><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><br/></td></tr>
</table>NetZwerghttps://wiki.qt.io/index.php?title=SimpleCrypt_algorithm_details&diff=18004&oldid=prevNetZwerg: Cleaning up, Tables, DocLinks, Layout...2015-06-16T10:09:47Z<p>Cleaning up, Tables, DocLinks, Layout...</p>
<a href="//wiki.qt.io/index.php?title=SimpleCrypt_algorithm_details&diff=18004&oldid=16109">Show changes</a>NetZwerghttps://wiki.qt.io/index.php?title=SimpleCrypt_algorithm_details&diff=16109&oldid=prevAutoSpider: Remove non-functioning "toc" command2015-04-17T12:36:59Z<p>Remove non-functioning "toc" command</p>
<table style="background-color: #fff; color: #202122;" data-mw="interface">
<col class="diff-marker" />
<col class="diff-content" />
<col class="diff-marker" />
<col class="diff-content" />
<tr class="diff-title" lang="en">
<td colspan="2" style="background-color: #fff; color: #202122; text-align: center;">← Older revision</td>
<td colspan="2" style="background-color: #fff; color: #202122; text-align: center;">Revision as of 12:36, 17 April 2015</td>
</tr><tr><td colspan="2" class="diff-lineno" id="mw-diff-left-l3">Line 3:</td>
<td colspan="2" class="diff-lineno">Line 3:</td></tr>
<tr><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>[[Category:Snippets]]</div></td><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>[[Category:Snippets]]</div></td></tr>
<tr><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><br/></td><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><br/></td></tr>
<tr><td class="diff-marker" data-marker="−"></td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div><del style="font-weight: bold; text-decoration: none;">[toc align_right="yes" depth="3"]</del></div></td><td colspan="2" class="diff-side-added"></td></tr>
<tr><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><br/></td><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><br/></td></tr>
<tr><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>= SimpleCrypt algorithm and format =</div></td><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>= SimpleCrypt algorithm and format =</div></td></tr>
</table>AutoSpiderhttps://wiki.qt.io/index.php?title=SimpleCrypt_algorithm_details&diff=10668&oldid=prevAutoSpider: Add "cleanup" tag2015-03-03T16:59:56Z<p>Add "cleanup" tag</p>
<table style="background-color: #fff; color: #202122;" data-mw="interface">
<col class="diff-marker" />
<col class="diff-content" />
<col class="diff-marker" />
<col class="diff-content" />
<tr class="diff-title" lang="en">
<td colspan="2" style="background-color: #fff; color: #202122; text-align: center;">← Older revision</td>
<td colspan="2" style="background-color: #fff; color: #202122; text-align: center;">Revision as of 16:59, 3 March 2015</td>
</tr><tr><td colspan="2" class="diff-lineno" id="mw-diff-left-l1">Line 1:</td>
<td colspan="2" class="diff-lineno">Line 1:</td></tr>
<tr><td colspan="2" class="diff-side-deleted"></td><td class="diff-marker" data-marker="+"></td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div><ins style="font-weight: bold; text-decoration: none;">{{Cleanup | reason=Auto-imported from ExpressionEngine.}}</ins></div></td></tr>
<tr><td colspan="2" class="diff-side-deleted"></td><td class="diff-marker" data-marker="+"></td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div><ins style="font-weight: bold; text-decoration: none;"></ins></div></td></tr>
<tr><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>[[Category:Snippets]]</div></td><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>[[Category:Snippets]]</div></td></tr>
<tr><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><br/></td><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><br/></td></tr>
</table>AutoSpiderhttps://wiki.qt.io/index.php?title=SimpleCrypt_algorithm_details&diff=6701&oldid=prevMaintenance script at 09:42, 25 February 20152015-02-25T09:42:21Z<p></p>
<a href="//wiki.qt.io/index.php?title=SimpleCrypt_algorithm_details&diff=6701&oldid=4177">Show changes</a>Maintenance scripthttps://wiki.qt.io/index.php?title=SimpleCrypt_algorithm_details&diff=4177&oldid=prevMaintenance script at 09:20, 24 February 20152015-02-24T09:20:40Z<p></p>
<a href="//wiki.qt.io/index.php?title=SimpleCrypt_algorithm_details&diff=4177&oldid=2096">Show changes</a>Maintenance scripthttps://wiki.qt.io/index.php?title=SimpleCrypt_algorithm_details&diff=2096&oldid=prevMaintenance script at 17:46, 14 January 20152015-01-14T17:46:48Z<p></p>
<p><b>New page</b></p><div>=SimpleCrypt algorithm and format=<br />
<br />
This page explains in more detail the format used by the [[Simple encryption|Simple_encryption]] code. The encryption and decryption code works from a <code>QByteArray</code> to a <code>QByteArray</code>. The options to use <code>QString</code>s are just provided for convenience. The first two sections detail how the stings and byte arrays correspond for both the plaintext and the cyphertexts. Then, the format of the binary <code>QByteArray</code> cyphertext is detailed.<br />
<br />
==String plaintext encoding==<br />
<br />
If a <code>QString</code> is used as the plaintext to encrypt, this string is encoded to a <code>QByteArray</code> by using the UTF8 codec. If a <code>QString</code> is requested as the result if a decryption action, the binary plaintext resulting from the decryption is interpretted using the same codec to construct a <code>QString</code><br />
<br />
==String cypher text format==<br />
<br />
<code>SimpleCrypt</code> can work with both <code>QString</code> and <code>QByteArray</code> cypher texts. The <code>QString</code> format is build on top of the <code>QByteArray</code> format. The <code>QString</code> is constructed from the <code>QByteArray</code> by creating a base64 encoded version of the binary cypher text, and using the <span class="caps">ASCII</span> codec to create a <code>QString</code> from this.<br />
<br />
For decryption, the reverse happens. The QString is translated into a binary format using the <span class="caps">ASCII</span> codec, and then the resulting <code>QByteArray</code> is decoded using the base64 codec into a binary cyper text.<br />
<br />
==Binary cypher text format==<br />
<br />
The binary cypher text (represented in a <code>QByteArray</code>), consists of a header and a payload section:<br />
<br />
{| class="infotable line"<br />
| '''bytes'''<br />
| '''description'''<br />
|-<br />
| style="text-align: left" | 0-1<br />
| style="text-align: left" | Header<br />
|-<br />
| style="text-align: left" | 2-N<br />
| style="text-align: left" | Payload. This section is encrypted.<br />
|}<br />
<br />
===Header===<br />
<br />
The header of the cypher text contains two fields: a version number, and a field with flags.<br />
<br />
{| class="infotable line"<br />
| '''bytes'''<br />
| '''description'''<br />
|-<br />
| style="text-align: left" | 0<br />
| style="text-align: left" | Version<br />
|-<br />
| style="text-align: left" | 1<br />
| style="text-align: left" | Flags<br />
|}<br />
<br />
====Version====<br />
<br />
The version number is a char. The current version number is 2.<br />
<br />
====Flags====<br />
<br />
The flags is a single byte bitfield. Each bit represents a flag that describes how the payload is to be interpreted.<br />
<br />
{| class="infotable line"<br />
| '''bit'''<br />
| '''value'''<br />
| '''description'''<br />
|-<br />
| style="text-align: left" | 0<br />
| 0×01<br />
| style="text-align: left" | Compression. If set, compression has been applied to the plaintext before encryption<br />
|-<br />
| style="text-align: left" | 1<br />
| 0×02<br />
| style="text-align: left" | Protection Checksum. If set, a CRC16-<span class="caps">CCITT</span> checksum, encoded in a quint16, has been used to protect data integrity.<br />
|-<br />
| style="text-align: left" | 2<br />
| 0×04<br />
| style="text-align: left" | Protection Hash. If set, an <span class="caps">SHA</span>-1 cryptograhpic hash (20 bytes long) has been used to protect data integrity.<br />
|}<br />
<br />
Bits 1 and 2 should not be set at the same time. If bit 1 has been set, bit 2 is ignored.<br />
<br />
Bits 3 to 7 are reserved for future use.<br />
<br />
===Payload===<br />
<br />
The payload data block’s contents are encrypted with a eight byte (quint64) key. They key is split up in eight chars, which are used consecutively starting again from key char 0 after key char 7 has been used. The <code>QByteArray</code> is encrypted by replacing each byte in the array with the value of that byte itself, <span class="caps">XOR</span>-ed with the key char, <span class="caps">XOR</span>-ed with the result of this operation for the previous byte in the <code>QByteArray</code> or 0 for byte 0 of the array. This operation can be reversed by <span class="caps">XOR</span>-ing the resulting cypher text byte again with both bytes that were used for the encryption phase.<br />
<br />
This results in the following encryption schema:<br />
<br />
{| class="infotable line"<br />
| '''byte'''<br />
| '''key byte'''<br />
| '''<span class="caps">XOR</span> value 2'''<br />
|-<br />
| style="text-align: left" | 0<br />
| 0<br />
| style="text-align: left" | the value 0<br />
|-<br />
| style="text-align: left" | 1<br />
| 1<br />
| style="text-align: left" | the result of this operation for byte 0<br />
|-<br />
| style="text-align: left" | 2<br />
| 2<br />
| style="text-align: left" | the result of this operation for byte 1<br />
|-<br />
| style="text-align: left" | …<br />
| …<br />
| …<br />
|-<br />
| style="text-align: left" | 7<br />
| 7<br />
| style="text-align: left" | the result of this operation for byte 6<br />
|-<br />
| style="text-align: left" | 8<br />
| 0<br />
| style="text-align: left" | the result of this operation for byte 7<br />
|-<br />
| style="text-align: left" | 9<br />
| 1<br />
| style="text-align: left" | the result of this operation for byte 8<br />
|-<br />
| …<br />
| …<br />
| …<br />
|-<br />
| style="text-align: left" | N<br />
| N mod 8<br />
| style="text-align: left" | the result of this operation for byte N-1<br />
|}<br />
<br />
The idea is that using the result of the previous byte as part of the key for this byte makes it impossible to use a simple attack that analyzes the cyphertext as 8 separate cyphertexts, each with its own 1-byte key. This is an attack possible on the basic vigenere-type cipher.<br />
<br />
===Decrypted payload===<br />
<br />
Once the payload data has been decrypted, it may need further processing before the plaintext is available and verified. What processing is needed, depends on the flags that are set in the header of the cyphertext.<br />
<br />
In case the Protection Checksum flag has been set, the layout of the decrypted payload looks like this:<br />
<br />
{| class="infotable line"<br />
| '''bytes'''<br />
| '''Value'''<br />
|-<br />
| style="text-align: left" | 0<br />
| style="text-align: left" | A random one byte number. This number is ignored after decryption.<br />
|-<br />
| style="text-align: left" | 1-2<br />
| style="text-align: left" | A quint16 containing a CRC16-<span class="caps">CCITT</span> checksum value of bytes 3-N.<br />
|-<br />
| style="text-align: left" | 3-N<br />
| style="text-align: left" | (Compressed) plaintext.<br />
|}<br />
<br />
In case the Protection Hash flag has been set, the layout of the decrypted payload looks like this:<br />
<br />
{| class="infotable line"<br />
| '''bytes'''<br />
| '''Value'''<br />
|-<br />
| style="text-align: left" | 0<br />
| style="text-align: left" | A random one byte number. This number is ignored after decryption.<br />
|-<br />
| style="text-align: left" | 1-20<br />
| style="text-align: left" | A 20 byte <span class="caps">SHA</span>-1 crypographic hash of bytes 21-N.<br />
|-<br />
| style="text-align: left" | 21-N<br />
| style="text-align: left" | (Compressed) plaintext.<br />
|}<br />
<br />
On decryption, the checksum or hash value must be checked by recalculating it for the (compressed) plaintext, and comparing that value with the data in the corresponding bytes of the decrypted payload. If they do not match, an error flag is set, and the decryption algorithm must return an empty byte array. If a wrong key is used, it is very unlikely that a checksum will still match. It is far more unlikely that the <span class="caps">SHA</span>-1 hash will still match. Note that the random leading number is not used for calculating the checksum or the <span class="caps">SHA</span>-1 hash.<br />
<br />
If neither of the Protection flags were set, the layout is simply:<br />
<br />
{| class="infotable line"<br />
| '''bytes'''<br />
| '''Value'''<br />
|-<br />
| style="text-align: left" | 0<br />
| style="text-align: left" | A random one byte number. This number is ignored after decryption.<br />
|-<br />
| style="text-align: left" | 1-N<br />
| style="text-align: left" | (Compressed) plaintext.<br />
|}<br />
<br />
====Rationale for using a leading random number====<br />
<br />
The <code>SimpleCrypt</code> algorithm uses the result of the encryption of the previous character as part of the encryption of the current character. That results in a situation that even if you have the same character at byte 0 and byte 7 of the plaintext, they will be most likely be encrypted to a different cyphertext. That makes it much harder to figure out the key used in the encryption if the attacker has the opportunity to feed in his own plaintext and can then see the resulting cyphertext. For byte 0 of the bytestream however, this is not possible. A (known) 0 value is used instead of the value of the previous byte. That leads to a weakness, especially if no Protection flags and no compression are used. The number of characters that are likely to be at the beginning of a password is not so big, thus reducing the amount of possibilities. That leads to an effective reduction in the key strength of several bits. Note that that is a loss of about an order of magnitude in strength.<br />
<br />
Putting a random number in front of the string makes it effectively impossible to use such heuristics to reduce the key strength, because there is no predictor for the random number in front (though, the situation is less than ideal, because of the use of the pseudo-random number generator. Achieving true randomness is ''very'' hard and well outside of te scope <code>SimpleCrypt</code>.)<br />
<br />
Note that also the use of either of the Protection modes and the use of compression add to the security of the cypher, as both decrease the predictability of the plaintext.<br />
<br />
===Compression===<br />
<br />
If the Compression flag is set, the data in the examples above is compressed using <code>qCompress</code>. The used compression level is 9 (maximum). On decryption, the data must then be uncompressed using <code>qUncompress</code>.<br />
<br />
===Result===<br />
<br />
The resulting binary plaintext is the data retreived from the decrypted payload or, if used, by the (de) compression step above.<br />
<br />
===Categories:===<br />
<br />
* [[:Category:snippets|snippets]]</div>Maintenance script