This commit is contained in:
louiscklaw
2025-01-31 19:28:21 +08:00
parent ce9a4aa9b3
commit 72bacdd6b5
168 changed files with 939668 additions and 0 deletions

Binary file not shown.

View File

@@ -0,0 +1,43 @@
<mxfile host="65bd71144e">
<diagram id="jUaFL9_61w-NF607VE0Q" name="Page-1">
<mxGraphModel dx="1130" dy="797" grid="1" gridSize="10" guides="1" tooltips="1" connect="1" arrows="1" fold="1" page="1" pageScale="1" pageWidth="850" pageHeight="1100" math="0" shadow="0">
<root>
<mxCell id="0"/>
<mxCell id="1" parent="0"/>
<mxCell id="6" style="edgeStyle=none;html=1;" parent="1" source="2" target="3" edge="1">
<mxGeometry relative="1" as="geometry"/>
</mxCell>
<mxCell id="2" value="Count letter occurence" style="whiteSpace=wrap;html=1;" parent="1" vertex="1">
<mxGeometry x="330" y="240" width="120" height="60" as="geometry"/>
</mxCell>
<mxCell id="7" style="edgeStyle=none;html=1;" parent="1" source="3" target="4" edge="1">
<mxGeometry relative="1" as="geometry"/>
</mxCell>
<mxCell id="3" value="find the letter with most occurence,&lt;br&gt;assign it to k" style="whiteSpace=wrap;html=1;" parent="1" vertex="1">
<mxGeometry x="330" y="340" width="120" height="60" as="geometry"/>
</mxCell>
<mxCell id="21" value="" style="edgeStyle=none;html=1;" parent="1" source="4" target="13" edge="1">
<mxGeometry relative="1" as="geometry"/>
</mxCell>
<mxCell id="4" value="decrypt file using the guessed k" style="whiteSpace=wrap;html=1;" parent="1" vertex="1">
<mxGeometry x="330" y="440" width="120" height="60" as="geometry"/>
</mxCell>
<mxCell id="16" value="" style="edgeStyle=none;html=1;" parent="1" source="11" target="15" edge="1">
<mxGeometry relative="1" as="geometry"/>
</mxCell>
<mxCell id="11" value="Start" style="ellipse;whiteSpace=wrap;html=1;rounded=1;strokeColor=default;" parent="1" vertex="1">
<mxGeometry x="330" y="60" width="120" height="40" as="geometry"/>
</mxCell>
<mxCell id="13" value="End" style="ellipse;whiteSpace=wrap;html=1;rounded=1;strokeColor=default;" parent="1" vertex="1">
<mxGeometry x="330" y="540" width="120" height="40" as="geometry"/>
</mxCell>
<mxCell id="17" value="" style="edgeStyle=none;html=1;" parent="1" source="15" target="2" edge="1">
<mxGeometry relative="1" as="geometry"/>
</mxCell>
<mxCell id="15" value="Open file to read&lt;br&gt;(i.e. ./wiki_e.txt)" style="whiteSpace=wrap;html=1;" parent="1" vertex="1">
<mxGeometry x="330" y="140" width="120" height="60" as="geometry"/>
</mxCell>
</root>
</mxGraphModel>
</diagram>
</mxfile>

BIN
banson_hker/deliver/diagram/decrypt_file.png (Stored with Git LFS) Normal file

Binary file not shown.

View File

@@ -0,0 +1,104 @@
<mxfile host="65bd71144e">
<diagram id="jUaFL9_61w-NF607VE0Q" name="Page-1">
<mxGraphModel dx="2055" dy="1449" grid="1" gridSize="10" guides="1" tooltips="1" connect="1" arrows="1" fold="1" page="1" pageScale="1" pageWidth="850" pageHeight="1100" math="0" shadow="0">
<root>
<mxCell id="0"/>
<mxCell id="1" parent="0"/>
<mxCell id="25" value="Yes" style="edgeStyle=none;html=1;" parent="1" source="21" target="24" edge="1">
<mxGeometry relative="1" as="geometry"/>
</mxCell>
<mxCell id="39" value="No" style="edgeStyle=none;html=1;entryX=0.5;entryY=0;entryDx=0;entryDy=0;exitX=1;exitY=0.5;exitDx=0;exitDy=0;" parent="1" source="21" target="38" edge="1">
<mxGeometry relative="1" as="geometry">
<Array as="points">
<mxPoint x="570" y="310"/>
</Array>
</mxGeometry>
</mxCell>
<mxCell id="21" value="Alphabat ?" style="rhombus;whiteSpace=wrap;html=1;" parent="1" vertex="1">
<mxGeometry x="320" y="270" width="80" height="80" as="geometry"/>
</mxCell>
<mxCell id="27" value="" style="edgeStyle=none;html=1;" parent="1" source="24" target="26" edge="1">
<mxGeometry relative="1" as="geometry"/>
</mxCell>
<mxCell id="24" value="Get offset according letter case&lt;br&gt;&lt;br&gt;i.e.&lt;br&gt;capital letter &quot;M&quot; will use &quot;A&quot; as offset&lt;br&gt;small letter &quot;m&quot; will use &quot;a&quot; as offset" style="whiteSpace=wrap;html=1;" parent="1" vertex="1">
<mxGeometry x="250" y="385" width="220" height="110" as="geometry"/>
</mxCell>
<mxCell id="29" value="" style="edgeStyle=none;html=1;" parent="1" source="26" target="28" edge="1">
<mxGeometry relative="1" as="geometry"/>
</mxCell>
<mxCell id="26" value="subtract letter ascii code (i.e. &quot;M&quot;) &lt;br&gt;to offset selected above(i.e. &quot;A&quot;)&lt;br&gt;&amp;nbsp;&lt;br&gt;apply guessed k" style="whiteSpace=wrap;html=1;" parent="1" vertex="1">
<mxGeometry x="250" y="530" width="220" height="80" as="geometry"/>
</mxCell>
<mxCell id="31" value="" style="edgeStyle=none;html=1;" parent="1" source="28" target="30" edge="1">
<mxGeometry relative="1" as="geometry"/>
</mxCell>
<mxCell id="28" value="wrap around if &lt;br&gt;less than 0 / more than 26 &lt;br&gt;by getting the remainder" style="whiteSpace=wrap;html=1;" parent="1" vertex="1">
<mxGeometry x="250" y="650" width="220" height="70" as="geometry"/>
</mxCell>
<mxCell id="33" value="" style="edgeStyle=none;html=1;" parent="1" source="30" target="32" edge="1">
<mxGeometry relative="1" as="geometry"/>
</mxCell>
<mxCell id="30" value="get letter back after shifting" style="whiteSpace=wrap;html=1;" parent="1" vertex="1">
<mxGeometry x="250" y="760" width="220" height="60" as="geometry"/>
</mxCell>
<mxCell id="32" value="Append to decrypted message" style="whiteSpace=wrap;html=1;" parent="1" vertex="1">
<mxGeometry x="300" y="850" width="120" height="60" as="geometry"/>
</mxCell>
<mxCell id="34" value="End" style="ellipse;whiteSpace=wrap;html=1;rounded=1;strokeColor=default;" parent="1" vertex="1">
<mxGeometry x="300" y="1050" width="120" height="40" as="geometry"/>
</mxCell>
<mxCell id="40" style="edgeStyle=none;html=1;entryX=1;entryY=0.5;entryDx=0;entryDy=0;" parent="1" source="38" target="32" edge="1">
<mxGeometry relative="1" as="geometry">
<Array as="points">
<mxPoint x="570" y="880"/>
</Array>
</mxGeometry>
</mxCell>
<mxCell id="38" value="number will not encrypt, append directly" style="whiteSpace=wrap;html=1;" parent="1" vertex="1">
<mxGeometry x="510" y="410" width="120" height="60" as="geometry"/>
</mxCell>
<mxCell id="41" value="" style="edgeStyle=none;html=1;" edge="1" parent="1" source="42" target="44">
<mxGeometry relative="1" as="geometry"/>
</mxCell>
<mxCell id="42" value="Start" style="ellipse;whiteSpace=wrap;html=1;rounded=1;strokeColor=default;" vertex="1" parent="1">
<mxGeometry x="300" y="20" width="120" height="40" as="geometry"/>
</mxCell>
<mxCell id="43" value="" style="edgeStyle=none;html=1;" edge="1" parent="1" source="44" target="46">
<mxGeometry relative="1" as="geometry"/>
</mxCell>
<mxCell id="44" value="loop through message by every letter" style="whiteSpace=wrap;html=1;" vertex="1" parent="1">
<mxGeometry x="300" y="90" width="120" height="60" as="geometry"/>
</mxCell>
<mxCell id="45" value="" style="edgeStyle=none;html=1;entryX=0.5;entryY=0;entryDx=0;entryDy=0;" edge="1" parent="1" source="46" target="21">
<mxGeometry relative="1" as="geometry">
<mxPoint x="360" y="250" as="targetPoint"/>
</mxGeometry>
</mxCell>
<mxCell id="46" value="get one character" style="whiteSpace=wrap;html=1;" vertex="1" parent="1">
<mxGeometry x="300" y="180" width="120" height="60" as="geometry"/>
</mxCell>
<mxCell id="47" value="" style="edgeStyle=none;html=1;exitX=0.5;exitY=1;exitDx=0;exitDy=0;" edge="1" parent="1" target="49" source="32">
<mxGeometry relative="1" as="geometry">
<mxPoint x="360" y="940" as="sourcePoint"/>
</mxGeometry>
</mxCell>
<mxCell id="48" value="Yes" style="edgeStyle=none;html=1;entryX=0.5;entryY=0;entryDx=0;entryDy=0;" edge="1" parent="1" source="49" target="34">
<mxGeometry relative="1" as="geometry">
<mxPoint x="400" y="1050" as="targetPoint"/>
</mxGeometry>
</mxCell>
<mxCell id="50" value="No" style="edgeStyle=none;html=1;entryX=1;entryY=0.5;entryDx=0;entryDy=0;" edge="1" parent="1" source="49" target="46">
<mxGeometry relative="1" as="geometry">
<Array as="points">
<mxPoint x="680" y="980"/>
<mxPoint x="680" y="210"/>
</Array>
</mxGeometry>
</mxCell>
<mxCell id="49" value="End of message ?" style="rhombus;whiteSpace=wrap;html=1;" vertex="1" parent="1">
<mxGeometry x="320" y="940" width="80" height="80" as="geometry"/>
</mxCell>
</root>
</mxGraphModel>
</diagram>
</mxfile>

BIN
banson_hker/deliver/diagram/decryption.png (Stored with Git LFS) Normal file

Binary file not shown.

View File

@@ -0,0 +1,55 @@
<mxfile host="65bd71144e">
<diagram id="jUaFL9_61w-NF607VE0Q" name="Page-1">
<mxGraphModel dx="1329" dy="938" grid="1" gridSize="10" guides="1" tooltips="1" connect="1" arrows="1" fold="1" page="1" pageScale="1" pageWidth="850" pageHeight="1100" math="0" shadow="0">
<root>
<mxCell id="0"/>
<mxCell id="1" parent="0"/>
<mxCell id="6" style="edgeStyle=none;html=1;" parent="1" source="2" target="3" edge="1">
<mxGeometry relative="1" as="geometry"/>
</mxCell>
<mxCell id="2" value="Generate file name according to user input&lt;br&gt;(i.e. ./wiki_e.txt)" style="whiteSpace=wrap;html=1;" parent="1" vertex="1">
<mxGeometry x="330" y="259" width="120" height="60" as="geometry"/>
</mxCell>
<mxCell id="7" style="edgeStyle=none;html=1;" parent="1" source="3" target="4" edge="1">
<mxGeometry relative="1" as="geometry"/>
</mxCell>
<mxCell id="3" value="open the file want to write&amp;nbsp;&lt;br&gt;(i.e. ./wiki_e.txt)" style="whiteSpace=wrap;html=1;" parent="1" vertex="1">
<mxGeometry x="330" y="363" width="120" height="60" as="geometry"/>
</mxCell>
<mxCell id="19" value="" style="edgeStyle=none;html=1;" parent="1" source="4" target="18" edge="1">
<mxGeometry relative="1" as="geometry"/>
</mxCell>
<mxCell id="4" value="clear file content" style="whiteSpace=wrap;html=1;" parent="1" vertex="1">
<mxGeometry x="330" y="467" width="120" height="60" as="geometry"/>
</mxCell>
<mxCell id="14" value="" style="edgeStyle=none;html=1;" parent="1" source="5" target="13" edge="1">
<mxGeometry relative="1" as="geometry"/>
</mxCell>
<mxCell id="5" value="write the encrpted content" style="whiteSpace=wrap;html=1;" parent="1" vertex="1">
<mxGeometry x="330" y="676" width="120" height="60" as="geometry"/>
</mxCell>
<mxCell id="16" value="" style="edgeStyle=none;html=1;" parent="1" source="11" target="15" edge="1">
<mxGeometry relative="1" as="geometry"/>
</mxCell>
<mxCell id="11" value="Start" style="ellipse;whiteSpace=wrap;html=1;rounded=1;strokeColor=default;" parent="1" vertex="1">
<mxGeometry x="330" y="60" width="120" height="40" as="geometry"/>
</mxCell>
<mxCell id="13" value="End" style="ellipse;whiteSpace=wrap;html=1;rounded=1;strokeColor=default;" parent="1" vertex="1">
<mxGeometry x="330" y="790" width="120" height="40" as="geometry"/>
</mxCell>
<mxCell id="17" value="" style="edgeStyle=none;html=1;" parent="1" source="15" target="2" edge="1">
<mxGeometry relative="1" as="geometry"/>
</mxCell>
<mxCell id="15" value="Get content from user inputted file&lt;br&gt;(i.e. ./wiki.txt)" style="whiteSpace=wrap;html=1;" parent="1" vertex="1">
<mxGeometry x="330" y="154" width="120" height="60" as="geometry"/>
</mxCell>
<mxCell id="20" value="" style="edgeStyle=none;html=1;" parent="1" source="18" target="5" edge="1">
<mxGeometry relative="1" as="geometry"/>
</mxCell>
<mxCell id="18" value="Generate encrypted content" style="whiteSpace=wrap;html=1;" parent="1" vertex="1">
<mxGeometry x="330" y="571" width="120" height="60" as="geometry"/>
</mxCell>
</root>
</mxGraphModel>
</diagram>
</mxfile>

BIN
banson_hker/deliver/diagram/encrypt_file.png (Stored with Git LFS) Normal file

Binary file not shown.

View File

@@ -0,0 +1,98 @@
<mxfile host="65bd71144e">
<diagram id="jUaFL9_61w-NF607VE0Q" name="Page-1">
<mxGraphModel dx="2260" dy="1594" grid="1" gridSize="10" guides="1" tooltips="1" connect="1" arrows="1" fold="1" page="1" pageScale="1" pageWidth="850" pageHeight="1100" math="0" shadow="0">
<root>
<mxCell id="0"/>
<mxCell id="1" parent="0"/>
<mxCell id="16" value="" style="edgeStyle=none;html=1;" parent="1" source="11" target="15" edge="1">
<mxGeometry relative="1" as="geometry"/>
</mxCell>
<mxCell id="11" value="Start" style="ellipse;whiteSpace=wrap;html=1;rounded=1;strokeColor=default;" parent="1" vertex="1">
<mxGeometry x="310" y="20" width="120" height="40" as="geometry"/>
</mxCell>
<mxCell id="46" value="" style="edgeStyle=none;html=1;" edge="1" parent="1" source="15" target="45">
<mxGeometry relative="1" as="geometry"/>
</mxCell>
<mxCell id="15" value="loop through message by every letter" style="whiteSpace=wrap;html=1;" parent="1" vertex="1">
<mxGeometry x="310" y="90" width="120" height="60" as="geometry"/>
</mxCell>
<mxCell id="25" value="Yes" style="edgeStyle=none;html=1;" parent="1" source="21" target="24" edge="1">
<mxGeometry relative="1" as="geometry"/>
</mxCell>
<mxCell id="39" value="No" style="edgeStyle=none;html=1;entryX=0.5;entryY=0;entryDx=0;entryDy=0;" parent="1" source="21" target="38" edge="1">
<mxGeometry relative="1" as="geometry">
<Array as="points">
<mxPoint x="580" y="310"/>
</Array>
</mxGeometry>
</mxCell>
<mxCell id="21" value="Alphabat ?" style="rhombus;whiteSpace=wrap;html=1;" parent="1" vertex="1">
<mxGeometry x="330" y="270" width="80" height="80" as="geometry"/>
</mxCell>
<mxCell id="27" value="" style="edgeStyle=none;html=1;" parent="1" source="24" target="26" edge="1">
<mxGeometry relative="1" as="geometry"/>
</mxCell>
<mxCell id="24" value="Get offset according letter case" style="whiteSpace=wrap;html=1;" parent="1" vertex="1">
<mxGeometry x="310" y="390" width="120" height="60" as="geometry"/>
</mxCell>
<mxCell id="29" value="" style="edgeStyle=none;html=1;" parent="1" source="26" target="28" edge="1">
<mxGeometry relative="1" as="geometry"/>
</mxCell>
<mxCell id="26" value="get distance between from letter to &quot;A&quot; or &quot;a&quot;" style="whiteSpace=wrap;html=1;" parent="1" vertex="1">
<mxGeometry x="310" y="490" width="120" height="60" as="geometry"/>
</mxCell>
<mxCell id="31" value="" style="edgeStyle=none;html=1;" parent="1" source="28" target="30" edge="1">
<mxGeometry relative="1" as="geometry"/>
</mxCell>
<mxCell id="28" value="wrap around if &lt;br&gt;less than 0 / more than 26 &lt;br&gt;by getting the modules&lt;br&gt;&lt;br&gt;apply shifting" style="whiteSpace=wrap;html=1;" parent="1" vertex="1">
<mxGeometry x="270" y="580" width="200" height="100" as="geometry"/>
</mxCell>
<mxCell id="33" value="" style="edgeStyle=none;html=1;" parent="1" source="30" target="32" edge="1">
<mxGeometry relative="1" as="geometry"/>
</mxCell>
<mxCell id="30" value="get letter back after shifting" style="whiteSpace=wrap;html=1;" parent="1" vertex="1">
<mxGeometry x="310" y="710" width="120" height="60" as="geometry"/>
</mxCell>
<mxCell id="42" value="" style="edgeStyle=none;html=1;" edge="1" parent="1" source="32" target="41">
<mxGeometry relative="1" as="geometry"/>
</mxCell>
<mxCell id="32" value="append to encrypted message" style="whiteSpace=wrap;html=1;" parent="1" vertex="1">
<mxGeometry x="310" y="810" width="120" height="60" as="geometry"/>
</mxCell>
<mxCell id="34" value="End" style="ellipse;whiteSpace=wrap;html=1;rounded=1;strokeColor=default;" parent="1" vertex="1">
<mxGeometry x="310" y="1020" width="120" height="40" as="geometry"/>
</mxCell>
<mxCell id="40" style="edgeStyle=none;html=1;entryX=1;entryY=0.5;entryDx=0;entryDy=0;" parent="1" source="38" target="32" edge="1">
<mxGeometry relative="1" as="geometry">
<Array as="points">
<mxPoint x="580" y="840"/>
</Array>
</mxGeometry>
</mxCell>
<mxCell id="38" value="number will not encrypt, append directly" style="whiteSpace=wrap;html=1;" parent="1" vertex="1">
<mxGeometry x="520" y="390" width="120" height="60" as="geometry"/>
</mxCell>
<mxCell id="43" value="Yes" style="edgeStyle=none;html=1;" edge="1" parent="1" source="41" target="34">
<mxGeometry relative="1" as="geometry"/>
</mxCell>
<mxCell id="44" value="No" style="edgeStyle=none;html=1;entryX=1;entryY=0.5;entryDx=0;entryDy=0;" edge="1" parent="1" source="41" target="45">
<mxGeometry relative="1" as="geometry">
<Array as="points">
<mxPoint x="680" y="940"/>
<mxPoint x="680" y="210"/>
</Array>
</mxGeometry>
</mxCell>
<mxCell id="41" value="End of message ?" style="rhombus;whiteSpace=wrap;html=1;" vertex="1" parent="1">
<mxGeometry x="330" y="900" width="80" height="80" as="geometry"/>
</mxCell>
<mxCell id="47" value="" style="edgeStyle=none;html=1;" edge="1" parent="1" source="45" target="21">
<mxGeometry relative="1" as="geometry"/>
</mxCell>
<mxCell id="45" value="get one character" style="whiteSpace=wrap;html=1;" vertex="1" parent="1">
<mxGeometry x="310" y="180" width="120" height="60" as="geometry"/>
</mxCell>
</root>
</mxGraphModel>
</diagram>
</mxfile>

BIN
banson_hker/deliver/diagram/encryption.png (Stored with Git LFS) Normal file

Binary file not shown.

View File

@@ -0,0 +1,93 @@
<mxfile host="65bd71144e">
<diagram id="jUaFL9_61w-NF607VE0Q" name="Page-1">
<mxGraphModel dx="1883" dy="1328" grid="1" gridSize="10" guides="1" tooltips="1" connect="1" arrows="1" fold="1" page="1" pageScale="1" pageWidth="850" pageHeight="1100" math="0" shadow="0">
<root>
<mxCell id="0"/>
<mxCell id="1" parent="0"/>
<mxCell id="25" value="Yes" style="edgeStyle=none;html=1;" parent="1" source="21" target="24" edge="1">
<mxGeometry relative="1" as="geometry"/>
</mxCell>
<mxCell id="39" value="No" style="edgeStyle=none;html=1;entryX=0.5;entryY=0;entryDx=0;entryDy=0;" parent="1" source="21" target="38" edge="1">
<mxGeometry relative="1" as="geometry">
<Array as="points">
<mxPoint x="530" y="470"/>
</Array>
</mxGeometry>
</mxCell>
<mxCell id="21" value="Alphabat ?" style="rhombus;whiteSpace=wrap;html=1;" parent="1" vertex="1">
<mxGeometry x="280" y="430" width="80" height="80" as="geometry"/>
</mxCell>
<mxCell id="27" value="" style="edgeStyle=none;html=1;" parent="1" source="24" target="26" edge="1">
<mxGeometry relative="1" as="geometry"/>
</mxCell>
<mxCell id="24" value="get the ascii code of all letter" style="whiteSpace=wrap;html=1;" parent="1" vertex="1">
<mxGeometry x="260" y="570" width="120" height="60" as="geometry"/>
</mxCell>
<mxCell id="29" value="" style="edgeStyle=none;html=1;" parent="1" source="26" edge="1">
<mxGeometry relative="1" as="geometry">
<mxPoint x="320" y="810" as="targetPoint"/>
</mxGeometry>
</mxCell>
<mxCell id="26" value="add 1 to the value indexed by the letter above" style="whiteSpace=wrap;html=1;" parent="1" vertex="1">
<mxGeometry x="260" y="680" width="120" height="60" as="geometry"/>
</mxCell>
<mxCell id="56" style="edgeStyle=none;html=1;entryX=0.5;entryY=0;entryDx=0;entryDy=0;" parent="1" source="38" edge="1">
<mxGeometry relative="1" as="geometry">
<mxPoint x="320" y="810" as="targetPoint"/>
<Array as="points">
<mxPoint x="530" y="770"/>
<mxPoint x="320" y="770"/>
</Array>
</mxGeometry>
</mxCell>
<mxCell id="38" value="number will not encrypt, skipping this step" style="whiteSpace=wrap;html=1;" parent="1" vertex="1">
<mxGeometry x="470" y="590" width="120" height="60" as="geometry"/>
</mxCell>
<mxCell id="43" value="" style="edgeStyle=none;html=1;" parent="1" target="21" edge="1">
<mxGeometry relative="1" as="geometry">
<mxPoint x="319.9999999999998" y="380" as="sourcePoint"/>
</mxGeometry>
</mxCell>
<mxCell id="45" value="" style="edgeStyle=none;html=1;" parent="1" source="46" target="48" edge="1">
<mxGeometry relative="1" as="geometry"/>
</mxCell>
<mxCell id="46" value="Start" style="ellipse;whiteSpace=wrap;html=1;rounded=1;strokeColor=default;" parent="1" vertex="1">
<mxGeometry x="260" y="70" width="120" height="40" as="geometry"/>
</mxCell>
<mxCell id="47" value="" style="edgeStyle=none;html=1;" parent="1" source="48" target="49" edge="1">
<mxGeometry relative="1" as="geometry"/>
</mxCell>
<mxCell id="48" value="setup a array of 26 to collect result&lt;br&gt;initialize them all to 0" style="whiteSpace=wrap;html=1;" parent="1" vertex="1">
<mxGeometry x="260" y="130" width="120" height="60" as="geometry"/>
</mxCell>
<mxCell id="60" value="" style="edgeStyle=none;html=1;" edge="1" parent="1" source="49" target="59">
<mxGeometry relative="1" as="geometry"/>
</mxCell>
<mxCell id="49" value="loop through message by every letter" style="whiteSpace=wrap;html=1;" parent="1" vertex="1">
<mxGeometry x="260" y="210" width="120" height="60" as="geometry"/>
</mxCell>
<mxCell id="50" value="End" style="ellipse;whiteSpace=wrap;html=1;rounded=1;strokeColor=default;" parent="1" vertex="1">
<mxGeometry x="260" y="940" width="120" height="40" as="geometry"/>
</mxCell>
<mxCell id="54" value="Yes" style="edgeStyle=none;html=1;" parent="1" source="52" target="50" edge="1">
<mxGeometry relative="1" as="geometry"/>
</mxCell>
<mxCell id="57" value="No" style="edgeStyle=none;html=1;entryX=1;entryY=0.5;entryDx=0;entryDy=0;" edge="1" parent="1" source="52" target="59">
<mxGeometry relative="1" as="geometry">
<mxPoint x="420" y="390" as="targetPoint"/>
<Array as="points">
<mxPoint x="670" y="850"/>
<mxPoint x="670" y="350"/>
</Array>
</mxGeometry>
</mxCell>
<mxCell id="52" value="End of message ?" style="rhombus;whiteSpace=wrap;html=1;" parent="1" vertex="1">
<mxGeometry x="280" y="810" width="80" height="80" as="geometry"/>
</mxCell>
<mxCell id="59" value="get one letter" style="whiteSpace=wrap;html=1;" vertex="1" parent="1">
<mxGeometry x="260" y="320" width="120" height="60" as="geometry"/>
</mxCell>
</root>
</mxGraphModel>
</diagram>
</mxfile>

BIN
banson_hker/deliver/diagram/letter_statistics.png (Stored with Git LFS) Normal file

Binary file not shown.

BIN
banson_hker/deliver/sc/decryption_demo.png (Stored with Git LFS) Normal file

Binary file not shown.

BIN
banson_hker/deliver/sc/encryption_step1.png (Stored with Git LFS) Normal file

Binary file not shown.

BIN
banson_hker/deliver/sc/encryption_step2.png (Stored with Git LFS) Normal file

Binary file not shown.

BIN
banson_hker/deliver/sc/home.png (Stored with Git LFS) Normal file

Binary file not shown.

BIN
banson_hker/deliver/sc/message_len_short_demo.png (Stored with Git LFS) Normal file

Binary file not shown.

BIN
banson_hker/deliver/sc/quit_demo.png (Stored with Git LFS) Normal file

Binary file not shown.

View File

@@ -0,0 +1,196 @@
#!/usr/bin/env python
import os,sys
ORD_a = ord('a') # 97
ORD_A = ord('A') # 65
def shift_cipher_encrypt(plaintext, key):
# apply encryption to text with given key
encrypted_message = ''
for char in plaintext:
if char.isalpha():
ascii_offset = ORD_A if char.isupper() else ORD_a # Determine ASCII offset based on uppercase or lowercase letter
# the comment shown below are the pseudo code, it demonstrate the ideas only
# let say the input is 'the' // without quote
# find distance of target character with reference to A or a
# i.e. t - a = 19 , h - a = 7 , e - a = 4
distance = ord(char) - ascii_offset
# [19,7,4] + [8,8,8] (key) = [27, 15, 12]
# Shift the character by adding the key and taking modulo 26 to wrap around
# [27,15,12] % [26,26,26] = [1,15,12] // get modules
shifted_distance = (distance + key) % 26
# [1,15,12] + [97,97,97] = [98,112,109]
# chr(98) , chr(112) , chr(109) = 'bpm'
shifted_char = chr(shifted_distance + ascii_offset)
# so: the -> bpm
encrypted_message += shifted_char
else:
# consider integer case, retain
encrypted_message += char
return encrypted_message
def shift_cipher_decrypt(ciphertext, key):
plaintext = ""
for char in ciphertext:
if char.isalpha():
ascii_offset = ORD_a if char.islower() else ORD_A # Determine ASCII offset based on lowercase or uppercase letter
# Calculate the distance of the target character from a or A
distance = ord(char) - ascii_offset
# apply shift, get the remainder of 26
shifted_distance = (distance - key) % 26
# Convert back to ASCII
decrypted_char = chr(shifted_distance + ascii_offset)
plaintext += decrypted_char
else:
# If it is not an alphabetic character, retain as is.
plaintext += char
return plaintext
def count_letter_e(txt_in):
# reserved function for demonstration purpose
occurence = 0
for char in txt_in:
if char.isalpha():
if char.lower() == 'e':
occurence += 1
return occurence
def count_most_occurrence_letter(txt_in):
# letter e, as stated have the most occurrence in the message by statistics.
# as 'Shift Cipher' is a encryption by letter shifting, the letters have good chance
# to have the most occurrence too in the encrypted text.
output = [0] * 26 # bucket for 26 letters
for char in txt_in:
if char.isalpha():
output[ord(char.lower()) - ORD_a] += 1
# output contains the statistics of paragraph letter by letter
return output
def find_max_occurrence(char_occurrences):
# get the letter of the most occurrences. i.e. m
# by subtract between this letter to e, k can be guess
# find max occurrence and its index
max_idx = char_occurrences.index(max(char_occurrences))
# subtract it with index of e -> 4
return max_idx - 4
def encrypt_file(file_path, key=8):
# open a file and apply encryption
output_file = file_path.replace('.txt','_e.txt')
# convert it to integer
key = int(key)
# open source file (plaintext)
with open(file_path,'r') as fi:
temp = ''.join(fi.readlines())
# open target file (encrypted text)
with open(output_file,'r+') as fo:
fo.truncate(0)
fo.writelines([shift_cipher_encrypt(temp, key)])
print(f'encryption done and file saved to {output_file}')
return
def decrypt_file(file_path):
# will open an encrypted file and decrypt it by a guessed key
with open(file_path,'r') as fi:
# beginning of the process
# read file and join the lines all
lines = fi.readlines()
e_temp = ''.join(lines)
characters_distribution = count_most_occurrence_letter(e_temp)
print('')
print('distribution of letters in encrypted text (case insensitive, from a to z)')
print(characters_distribution)
print('')
guess_k = find_max_occurrence(characters_distribution)
print(f'guessed k: {guess_k}')
print('')
print('decrypted text:')
decrypted_text = shift_cipher_decrypt(e_temp, guess_k)
print(decrypted_text)
while True:
# show menu
print()
print("1. Encrypt File")
print("2. Decrypt File")
print("q. quit")
print()
option = input("Select an option (1/2/q): ")
if option == "1":
# run if user want to encrypt file
# check if user entered a file
user_not_enter_file = True
while user_not_enter_file:
file_path = input("Enter the path of the file to encrypt: ")
if len(file_path) > 0:
if os.path.exists(file_path):
user_not_enter_file = False
else:
print('sorry but the file not exist')
else:
print('please enter a file path')
# check if user entered a key
user_not_enter_key = True
while user_not_enter_key:
key = input("Enter the key(k) to encrypt: ")
if (len(key) > 0):
user_not_enter_key = False
else:
print('please enter a key(k)')
if os.path.exists(file_path):
encrypt_file(file_path, key)
print('encryption done')
else:
print("File does not exist.")
elif option == "2":
# run if user want to decrypt file
file_path = input("Enter the path of the file to decrypt: ")
if os.path.exists(file_path):
decrypt_file(file_path)
print('decryption done')
else:
print("File does not exist.")
elif option.lower() == "q":
print('quitting bye ...')
break
else:
print('')
print('ERROR !')
print('please enter either [1/2/q]')
input("press a key to continue ...")
print('')
print("Exiting...")

View File

@@ -0,0 +1 @@
python ./shift_cipher_encrypter.py

View File

@@ -0,0 +1,8 @@
Ref: https://en.wikipedia.org/wiki/Hong_Kong
Hong Kong was established as a colony of the British Empire after the Qing Empire ceded Hong Kong Island in 18411842. The colony expanded to the Kowloon Peninsula in 1860 and was further extended when the United Kingdom obtained a 99-year lease of the New Territories in 1898. Hong Kong was briefly occupied by Japan from 1941 to 1945 during World War II. The whole territory was transferred from the United Kingdom to China in 1997. Hong Kong maintains separate governing and economic systems from that of mainland China under the principle of "one country, two systems".[f]
Originally a sparsely populated area of farming and fishing villages,[18][19] the territory is now one of the world's most significant financial centres and commercial ports. Hong Kong is the world's fourth-ranked global financial centre, ninth-largest exporter, and eighth-largest importer. Its currency, the Hong Kong dollar, is the eighth most traded currency in the world. Home to the second-highest number of billionaires of any city in the world, Hong Kong has the largest concentration of ultra high-net-worth individuals. Although the city has one of the highest per capita incomes in the world, severe income inequality exists among the population. Despite having the largest number of skyscrapers of any city in the world, housing in Hong Kong has been well-documented to experience a chronic persistent shortage.
Hong Kong is a highly developed territory and has a Human Development Index (HDI) of 0.952, ranking fourth in the world. The city has the second highest life expectancy in the world, and a public transport rate exceeding 90%.
around 261 words

View File

@@ -0,0 +1,4 @@
Jwx: zllhk://wf.oacahwvas.gjy/oaca/Zgfy_Cgfy
sjgmfv 261 ogjvk