update,
This commit is contained in:
19
phase1-fix/deliver/Problem to solve.txt
Normal file
19
phase1-fix/deliver/Problem to solve.txt
Normal file
@@ -0,0 +1,19 @@
|
||||
1.如果淨係放嗰個txt file佢唔識encrypt 後output 個encrypt後嘅document .即係我如果delete咗wiki_e.txt佢唔識自己再output。需要人手開一個新txt document
|
||||
|
||||
詳情可以睇 Problem1.mp4
|
||||
|
||||
2. 1.如果篇文有兩個相同(無論係相同或者多過)字數嘅Alphabet 出現 呢個時候個program就會encrypt錯。例如將「people 」呢隻字打到200字 「P」同「E」嘅數量係一樣
|
||||
所以encrypt完之後變出嚟嘅亂碼 再decrypt唔會變返「People」所以要搵解決方法做到點樣先可以知道decrypt gen出嚟嘅key(k)係準確。
|
||||
|
||||
詳情可以睇Problem2 (Alphabet E is the same with P).mp4 Problem 2( Alphabet P is more than E and the guess of Key is error).mp4
|
||||
|
||||
阿sir指定話要將呢個problem寫入report睇下點樣solve同埋點解會出現呢個情況. Thanks very much
|
||||
|
||||
|
||||
3.個Guildline要求無論係Uppercase定LowerCase都要直接將佢變成Uppercase但係只有文字轉Uppercase標點符號同埋spaces唔會改變。
|
||||
|
||||
即係gen出嚟嘅亂碼會係全大階。 (咁係唔係即係delete咗Lowercase段code就得?)
|
||||
|
||||
4.要加多個flow chart喺report入面係整合曬成個program.
|
||||
|
||||
Thanks a lot for helping me.!!!!!!
|
BIN
phase1-fix/deliver/Report.docx
Normal file
BIN
phase1-fix/deliver/Report.docx
Normal file
Binary file not shown.
BIN
phase1-fix/deliver/Report_new.docx
Normal file
BIN
phase1-fix/deliver/Report_new.docx
Normal file
Binary file not shown.
1
phase1-fix/deliver/aaaaa.txt
Normal file
1
phase1-fix/deliver/aaaaa.txt
Normal file
@@ -0,0 +1 @@
|
||||
aaaaa
|
1
phase1-fix/deliver/apple.txt
Normal file
1
phase1-fix/deliver/apple.txt
Normal file
@@ -0,0 +1 @@
|
||||
apple apple apple apple apple apple apple apple apple apple apple apple apple apple apple apple apple apple apple apple apple apple apple apple apple apple apple apple apple apple apple apple apple apple apple apple
|
1
phase1-fix/deliver/apple_e.txt
Normal file
1
phase1-fix/deliver/apple_e.txt
Normal file
@@ -0,0 +1 @@
|
||||
ETTPI ETTPI ETTPI
|
79
phase1-fix/deliver/diagram/check_words_valid.drawio
Normal file
79
phase1-fix/deliver/diagram/check_words_valid.drawio
Normal file
@@ -0,0 +1,79 @@
|
||||
<mxfile host="65bd71144e">
|
||||
<diagram id="jUaFL9_61w-NF607VE0Q" name="Page-1">
|
||||
<mxGraphModel dx="329" dy="382" 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="34" value="End" style="ellipse;whiteSpace=wrap;html=1;rounded=1;strokeColor=default;" parent="1" vertex="1">
|
||||
<mxGeometry x="255" y="880" width="120" height="40" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="41" value="" style="edgeStyle=none;html=1;" parent="1" source="42" target="44" edge="1">
|
||||
<mxGeometry relative="1" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="42" value="Start" style="ellipse;whiteSpace=wrap;html=1;rounded=1;strokeColor=default;" parent="1" vertex="1">
|
||||
<mxGeometry x="255" y="180" width="120" height="40" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="43" value="" style="edgeStyle=none;html=1;" parent="1" source="44" target="46" edge="1">
|
||||
<mxGeometry relative="1" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="44" value="loop through message by every word" style="whiteSpace=wrap;html=1;" parent="1" vertex="1">
|
||||
<mxGeometry x="255" y="250" width="120" height="60" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="55" value="" style="edgeStyle=none;html=1;" parent="1" source="46" target="54" edge="1">
|
||||
<mxGeometry relative="1" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="46" value="perform lookup to find if the word match in dictionary" style="whiteSpace=wrap;html=1;" parent="1" vertex="1">
|
||||
<mxGeometry x="255" y="360" width="120" height="60" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="53" value="Yes" style="edgeStyle=none;html=1;" parent="1" target="34" edge="1">
|
||||
<mxGeometry relative="1" as="geometry">
|
||||
<mxPoint x="315" y="840" as="sourcePoint"/>
|
||||
</mxGeometry>
|
||||
</mxCell>
|
||||
<mxCell id="58" value="Yes" style="edgeStyle=none;html=1;entryX=0.5;entryY=0;entryDx=0;entryDy=0;" parent="1" source="54" target="59" edge="1">
|
||||
<mxGeometry relative="1" as="geometry">
|
||||
<mxPoint x="315" y="630" as="targetPoint"/>
|
||||
</mxGeometry>
|
||||
</mxCell>
|
||||
<mxCell id="63" value="No" style="edgeStyle=none;html=1;" parent="1" source="54" target="62" edge="1">
|
||||
<mxGeometry relative="1" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="54" value="Match ?" style="rhombus;whiteSpace=wrap;html=1;" parent="1" vertex="1">
|
||||
<mxGeometry x="275" y="490" width="80" height="80" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="61" value="" style="edgeStyle=none;html=1;" parent="1" source="59" target="60" edge="1">
|
||||
<mxGeometry relative="1" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="59" value="Store positive result in array" style="whiteSpace=wrap;html=1;" parent="1" vertex="1">
|
||||
<mxGeometry x="255" y="630" width="120" height="60" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="60" value="Message <br>end ?" style="rhombus;whiteSpace=wrap;html=1;" parent="1" vertex="1">
|
||||
<mxGeometry x="275" y="760" width="80" height="80" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="62" value="store negative result in array" style="whiteSpace=wrap;html=1;" parent="1" vertex="1">
|
||||
<mxGeometry x="415" y="500" width="120" height="60" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="64" value="" style="edgeStyle=none;orthogonalLoop=1;jettySize=auto;html=1;exitX=0.5;exitY=1;exitDx=0;exitDy=0;" parent="1" source="62" edge="1">
|
||||
<mxGeometry width="80" relative="1" as="geometry">
|
||||
<mxPoint x="425" y="610" as="sourcePoint"/>
|
||||
<mxPoint x="315" y="720" as="targetPoint"/>
|
||||
<Array as="points">
|
||||
<mxPoint x="475" y="720"/>
|
||||
</Array>
|
||||
</mxGeometry>
|
||||
</mxCell>
|
||||
<mxCell id="65" value="No" style="edgeStyle=none;orthogonalLoop=1;jettySize=auto;html=1;exitX=1;exitY=0.5;exitDx=0;exitDy=0;" parent="1" source="60" edge="1">
|
||||
<mxGeometry x="-0.8571" width="80" relative="1" as="geometry">
|
||||
<mxPoint x="415" y="490" as="sourcePoint"/>
|
||||
<mxPoint x="315" y="340" as="targetPoint"/>
|
||||
<Array as="points">
|
||||
<mxPoint x="595" y="800"/>
|
||||
<mxPoint x="595" y="340"/>
|
||||
</Array>
|
||||
<mxPoint as="offset"/>
|
||||
</mxGeometry>
|
||||
</mxCell>
|
||||
</root>
|
||||
</mxGraphModel>
|
||||
</diagram>
|
||||
</mxfile>
|
BIN
phase1-fix/deliver/diagram/check_words_valid.png
(Stored with Git LFS)
Normal file
BIN
phase1-fix/deliver/diagram/check_words_valid.png
(Stored with Git LFS)
Normal file
Binary file not shown.
81
phase1-fix/deliver/diagram/decrypt_by_bruce_force.drawio
Normal file
81
phase1-fix/deliver/diagram/decrypt_by_bruce_force.drawio
Normal file
@@ -0,0 +1,81 @@
|
||||
<mxfile host="65bd71144e">
|
||||
<diagram id="jUaFL9_61w-NF607VE0Q" name="Page-1">
|
||||
<mxGraphModel dx="493" dy="803" 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="34" value="End" style="ellipse;whiteSpace=wrap;html=1;rounded=1;strokeColor=default;" parent="1" vertex="1">
|
||||
<mxGeometry x="285" y="900" width="120" height="40" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="41" value="" style="edgeStyle=none;html=1;" parent="1" source="42" edge="1">
|
||||
<mxGeometry relative="1" as="geometry">
|
||||
<mxPoint x="345" y="230" as="targetPoint"/>
|
||||
</mxGeometry>
|
||||
</mxCell>
|
||||
<mxCell id="42" value="Start" style="ellipse;whiteSpace=wrap;html=1;rounded=1;strokeColor=default;" parent="1" vertex="1">
|
||||
<mxGeometry x="285" y="160" width="120" height="40" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="78" value="" style="edgeStyle=none;html=1;" parent="1" source="76" target="77" edge="1">
|
||||
<mxGeometry relative="1" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="76" value="initialize k = 0" style="whiteSpace=wrap;html=1;" parent="1" vertex="1">
|
||||
<mxGeometry x="285" y="230" width="120" height="60" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="80" value="" style="edgeStyle=none;html=1;" parent="1" source="77" target="79" edge="1">
|
||||
<mxGeometry relative="1" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="77" value="Try decrypt using k" style="whiteSpace=wrap;html=1;" parent="1" vertex="1">
|
||||
<mxGeometry x="285" y="370" width="120" height="60" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="82" value="" style="edgeStyle=none;html=1;" parent="1" source="79" target="81" edge="1">
|
||||
<mxGeometry relative="1" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="79" value="Dictionary lookup the decrupted message" style="whiteSpace=wrap;html=1;" parent="1" vertex="1">
|
||||
<mxGeometry x="285" y="510" width="120" height="60" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="83" value="No" style="edgeStyle=none;html=1;" parent="1" source="81" target="34" edge="1">
|
||||
<mxGeometry relative="1" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="85" value="yes" style="edgeStyle=none;html=1;" parent="1" source="81" target="84" edge="1">
|
||||
<mxGeometry relative="1" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="81" value="Result positibe ?" style="rhombus;whiteSpace=wrap;html=1;" parent="1" vertex="1">
|
||||
<mxGeometry x="305" y="640" width="80" height="80" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="87" value="Yes" style="edgeStyle=none;html=1;" parent="1" source="84" target="86" edge="1">
|
||||
<mxGeometry relative="1" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="90" value="No" style="edgeStyle=none;html=1;" parent="1" source="84" target="89" edge="1">
|
||||
<mxGeometry relative="1" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="84" value="k &gt; 25?" style="rhombus;whiteSpace=wrap;html=1;" parent="1" vertex="1">
|
||||
<mxGeometry x="465" y="640" width="80" height="80" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="86" value="cannot decrupt message by bruce force" style="whiteSpace=wrap;html=1;" parent="1" vertex="1">
|
||||
<mxGeometry x="445" y="780" width="120" height="60" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="88" value="" style="edgeStyle=none;orthogonalLoop=1;jettySize=auto;html=1;exitX=0.5;exitY=1;exitDx=0;exitDy=0;" parent="1" source="86" edge="1">
|
||||
<mxGeometry width="80" relative="1" as="geometry">
|
||||
<mxPoint x="475" y="740" as="sourcePoint"/>
|
||||
<mxPoint x="345" y="870" as="targetPoint"/>
|
||||
<Array as="points">
|
||||
<mxPoint x="505" y="870"/>
|
||||
</Array>
|
||||
</mxGeometry>
|
||||
</mxCell>
|
||||
<mxCell id="89" value="still possible to decrypt<br>k = k + 1" style="whiteSpace=wrap;html=1;" parent="1" vertex="1">
|
||||
<mxGeometry x="445" y="490" width="120" height="60" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="91" value="" style="edgeStyle=none;orthogonalLoop=1;jettySize=auto;html=1;exitX=0.5;exitY=0;exitDx=0;exitDy=0;entryX=1;entryY=0.5;entryDx=0;entryDy=0;" parent="1" source="89" target="77" edge="1">
|
||||
<mxGeometry width="80" relative="1" as="geometry">
|
||||
<mxPoint x="665" y="290" as="sourcePoint"/>
|
||||
<mxPoint x="745" y="290" as="targetPoint"/>
|
||||
<Array as="points">
|
||||
<mxPoint x="505" y="400"/>
|
||||
</Array>
|
||||
</mxGeometry>
|
||||
</mxCell>
|
||||
</root>
|
||||
</mxGraphModel>
|
||||
</diagram>
|
||||
</mxfile>
|
BIN
phase1-fix/deliver/diagram/decrypt_by_bruce_force.png
(Stored with Git LFS)
Normal file
BIN
phase1-fix/deliver/diagram/decrypt_by_bruce_force.png
(Stored with Git LFS)
Normal file
Binary file not shown.
108
phase1-fix/deliver/diagram/decrypt_by_letter_occurrence.drawio
Normal file
108
phase1-fix/deliver/diagram/decrypt_by_letter_occurrence.drawio
Normal file
@@ -0,0 +1,108 @@
|
||||
<mxfile host="65bd71144e">
|
||||
<diagram id="jUaFL9_61w-NF607VE0Q" name="Page-1">
|
||||
<mxGraphModel dx="1232" dy="803" 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 of letter<br><br>i.e.<br>capital letter "M" will use "A" 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. "M") <br>to offset selected above(i.e. "A")<br>&nbsp;<br>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 <br>less than 0 / more than 26 <br>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<br>(decrypted letter)" 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="1160" 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;" parent="1" source="42" target="44" edge="1">
|
||||
<mxGeometry relative="1" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="42" value="Start" style="ellipse;whiteSpace=wrap;html=1;rounded=1;strokeColor=default;" parent="1" vertex="1">
|
||||
<mxGeometry x="300" y="20" width="120" height="40" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="43" value="" style="edgeStyle=none;html=1;" parent="1" source="44" target="46" edge="1">
|
||||
<mxGeometry relative="1" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="44" value="loop through message by every letter" style="whiteSpace=wrap;html=1;" parent="1" vertex="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;" parent="1" source="46" target="21" edge="1">
|
||||
<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;" parent="1" vertex="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;" parent="1" source="32" target="49" edge="1">
|
||||
<mxGeometry relative="1" as="geometry">
|
||||
<mxPoint x="360" y="940" as="sourcePoint"/>
|
||||
</mxGeometry>
|
||||
</mxCell>
|
||||
<mxCell id="50" value="No" style="edgeStyle=none;html=1;entryX=1;entryY=0.5;entryDx=0;entryDy=0;" parent="1" source="49" target="46" edge="1">
|
||||
<mxGeometry relative="1" as="geometry">
|
||||
<Array as="points">
|
||||
<mxPoint x="680" y="980"/>
|
||||
<mxPoint x="680" y="210"/>
|
||||
</Array>
|
||||
</mxGeometry>
|
||||
</mxCell>
|
||||
<mxCell id="52" value="yes" style="edgeStyle=none;html=1;" edge="1" parent="1" source="49" target="51">
|
||||
<mxGeometry relative="1" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="49" value="End of message ?" style="rhombus;whiteSpace=wrap;html=1;" parent="1" vertex="1">
|
||||
<mxGeometry x="320" y="940" width="80" height="80" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="53" value="" style="edgeStyle=none;html=1;" edge="1" parent="1" source="51" target="34">
|
||||
<mxGeometry relative="1" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="51" value="Perform dictionary<br>lookup, get score" style="whiteSpace=wrap;html=1;" vertex="1" parent="1">
|
||||
<mxGeometry x="300" y="1060" width="120" height="60" as="geometry"/>
|
||||
</mxCell>
|
||||
</root>
|
||||
</mxGraphModel>
|
||||
</diagram>
|
||||
</mxfile>
|
BIN
phase1-fix/deliver/diagram/decrypt_by_letter_occurrence.png
(Stored with Git LFS)
Normal file
BIN
phase1-fix/deliver/diagram/decrypt_by_letter_occurrence.png
(Stored with Git LFS)
Normal file
Binary file not shown.
76
phase1-fix/deliver/diagram/decrypt_file.drawio
Normal file
76
phase1-fix/deliver/diagram/decrypt_file.drawio
Normal file
@@ -0,0 +1,76 @@
|
||||
<mxfile host="65bd71144e">
|
||||
<diagram id="jUaFL9_61w-NF607VE0Q" name="Page-1">
|
||||
<mxGraphModel dx="283" dy="185" 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="" style="edgeStyle=none;html=1;" parent="1" source="23" target="24" edge="1">
|
||||
<mxGeometry relative="1" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="23" value="Start" style="ellipse;whiteSpace=wrap;html=1;rounded=1;strokeColor=default;" parent="1" vertex="1">
|
||||
<mxGeometry x="280" y="140" width="120" height="40" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="32" value="" style="edgeStyle=none;html=1;" parent="1" source="24" target="26" edge="1">
|
||||
<mxGeometry relative="1" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="24" value="Try to decrypt by occurrence" style="whiteSpace=wrap;html=1;" parent="1" vertex="1">
|
||||
<mxGeometry x="280" y="230" width="120" height="60" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="33" value="No" style="edgeStyle=none;html=1;" parent="1" source="26" target="27" edge="1">
|
||||
<mxGeometry relative="1" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="38" value="Yes" style="edgeStyle=none;html=1;entryX=0.5;entryY=0;entryDx=0;entryDy=0;" parent="1" source="26" target="39" edge="1">
|
||||
<mxGeometry x="-0.7551" relative="1" as="geometry">
|
||||
<mxPoint x="440" y="380" as="targetPoint"/>
|
||||
<Array as="points">
|
||||
<mxPoint x="510" y="380"/>
|
||||
</Array>
|
||||
<mxPoint as="offset"/>
|
||||
</mxGeometry>
|
||||
</mxCell>
|
||||
<mxCell id="26" value="Decryption&nbsp;<br>pass ?" style="rhombus;whiteSpace=wrap;html=1;" parent="1" vertex="1">
|
||||
<mxGeometry x="300" y="340" width="80" height="80" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="34" value="" style="edgeStyle=none;html=1;" parent="1" source="27" target="29" edge="1">
|
||||
<mxGeometry relative="1" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="27" value="Try decrypt by bruce force" style="whiteSpace=wrap;html=1;" parent="1" vertex="1">
|
||||
<mxGeometry x="280" y="490" width="120" height="60" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="35" value="No" style="edgeStyle=none;html=1;" parent="1" source="29" target="30" edge="1">
|
||||
<mxGeometry relative="1" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="29" value="Decryption&nbsp;<br>pass ?" style="rhombus;whiteSpace=wrap;html=1;" parent="1" vertex="1">
|
||||
<mxGeometry x="300" y="610" width="80" height="80" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="36" value="" style="edgeStyle=none;html=1;" parent="1" source="30" target="31" edge="1">
|
||||
<mxGeometry relative="1" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="30" value="Show user cannot decrypt message" style="whiteSpace=wrap;html=1;" parent="1" vertex="1">
|
||||
<mxGeometry x="280" y="740" width="120" height="60" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="31" value="End" style="ellipse;whiteSpace=wrap;html=1;rounded=1;strokeColor=default;" parent="1" vertex="1">
|
||||
<mxGeometry x="280" y="860" width="120" height="40" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="41" value="" style="edgeStyle=none;html=1;" parent="1" source="39" edge="1">
|
||||
<mxGeometry relative="1" as="geometry">
|
||||
<mxPoint x="340" y="840" as="targetPoint"/>
|
||||
<Array as="points">
|
||||
<mxPoint x="510" y="840"/>
|
||||
</Array>
|
||||
</mxGeometry>
|
||||
</mxCell>
|
||||
<mxCell id="39" value="Show user decrypted message" style="whiteSpace=wrap;html=1;" parent="1" vertex="1">
|
||||
<mxGeometry x="450" y="740" width="120" height="60" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="42" value="Yes" style="edgeStyle=none;orthogonalLoop=1;jettySize=auto;html=1;exitX=1;exitY=0.5;exitDx=0;exitDy=0;" parent="1" source="29" edge="1">
|
||||
<mxGeometry width="80" relative="1" as="geometry">
|
||||
<mxPoint x="430" y="620" as="sourcePoint"/>
|
||||
<mxPoint x="510" y="650" as="targetPoint"/>
|
||||
<Array as="points"/>
|
||||
</mxGeometry>
|
||||
</mxCell>
|
||||
</root>
|
||||
</mxGraphModel>
|
||||
</diagram>
|
||||
</mxfile>
|
BIN
phase1-fix/deliver/diagram/decrypt_file.png
(Stored with Git LFS)
Normal file
BIN
phase1-fix/deliver/diagram/decrypt_file.png
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
phase1-fix/deliver/diagram/decrypt_file.png1
Normal file
BIN
phase1-fix/deliver/diagram/decrypt_file.png1
Normal file
Binary file not shown.
After Width: | Height: | Size: 67 KiB |
55
phase1-fix/deliver/diagram/encrypt_file.drawio
Normal file
55
phase1-fix/deliver/diagram/encrypt_file.drawio
Normal 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<br>(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&nbsp;<br>(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<br>(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
phase1-fix/deliver/diagram/encrypt_file.png
(Stored with Git LFS)
Normal file
BIN
phase1-fix/deliver/diagram/encrypt_file.png
(Stored with Git LFS)
Normal file
Binary file not shown.
100
phase1-fix/deliver/diagram/encryption.drawio
Normal file
100
phase1-fix/deliver/diagram/encryption.drawio
Normal file
@@ -0,0 +1,100 @@
|
||||
<mxfile host="65bd71144e">
|
||||
<diagram id="jUaFL9_61w-NF607VE0Q" name="Page-1">
|
||||
<mxGraphModel dx="1760" dy="1147" 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;" parent="1" source="15" target="45" edge="1">
|
||||
<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 x="-0.76" relative="1" as="geometry">
|
||||
<Array as="points">
|
||||
<mxPoint x="580" y="310"/>
|
||||
</Array>
|
||||
<mxPoint as="offset"/>
|
||||
</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 "A"" 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 <br>less than 0 / more than 26 <br>by getting the modules<br><br>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;" parent="1" source="32" target="41" edge="1">
|
||||
<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;" parent="1" source="41" target="34" edge="1">
|
||||
<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;" parent="1" source="41" target="45" edge="1">
|
||||
<mxGeometry x="-0.888" relative="1" as="geometry">
|
||||
<Array as="points">
|
||||
<mxPoint x="680" y="940"/>
|
||||
<mxPoint x="680" y="210"/>
|
||||
</Array>
|
||||
<mxPoint as="offset"/>
|
||||
</mxGeometry>
|
||||
</mxCell>
|
||||
<mxCell id="41" value="End of message ?" style="rhombus;whiteSpace=wrap;html=1;" parent="1" vertex="1">
|
||||
<mxGeometry x="330" y="900" width="80" height="80" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="47" value="" style="edgeStyle=none;html=1;" parent="1" source="45" target="21" edge="1">
|
||||
<mxGeometry relative="1" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="45" value="get one character" style="whiteSpace=wrap;html=1;" parent="1" vertex="1">
|
||||
<mxGeometry x="310" y="180" width="120" height="60" as="geometry"/>
|
||||
</mxCell>
|
||||
</root>
|
||||
</mxGraphModel>
|
||||
</diagram>
|
||||
</mxfile>
|
BIN
phase1-fix/deliver/diagram/encryption.png
(Stored with Git LFS)
Normal file
BIN
phase1-fix/deliver/diagram/encryption.png
(Stored with Git LFS)
Normal file
Binary file not shown.
108
phase1-fix/deliver/diagram/helloworld.drawio
Normal file
108
phase1-fix/deliver/diagram/helloworld.drawio
Normal file
@@ -0,0 +1,108 @@
|
||||
<mxfile host="65bd71144e">
|
||||
<diagram id="jUaFL9_61w-NF607VE0Q" name="Page-1">
|
||||
<mxGraphModel dx="1232" dy="803" 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 of letter<br><br>i.e.<br>capital letter "M" will use "A" 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. "M") <br>to offset selected above(i.e. "A")<br>&nbsp;<br>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 <br>less than 0 / more than 26 <br>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<br>(decrypted letter)" 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="1160" 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;" parent="1" source="42" target="44" edge="1">
|
||||
<mxGeometry relative="1" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="42" value="Start" style="ellipse;whiteSpace=wrap;html=1;rounded=1;strokeColor=default;" parent="1" vertex="1">
|
||||
<mxGeometry x="300" y="20" width="120" height="40" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="43" value="" style="edgeStyle=none;html=1;" parent="1" source="44" target="46" edge="1">
|
||||
<mxGeometry relative="1" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="44" value="loop through message by every letter" style="whiteSpace=wrap;html=1;" parent="1" vertex="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;" parent="1" source="46" target="21" edge="1">
|
||||
<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;" parent="1" vertex="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;" parent="1" source="32" target="49" edge="1">
|
||||
<mxGeometry relative="1" as="geometry">
|
||||
<mxPoint x="360" y="940" as="sourcePoint"/>
|
||||
</mxGeometry>
|
||||
</mxCell>
|
||||
<mxCell id="50" value="No" style="edgeStyle=none;html=1;entryX=1;entryY=0.5;entryDx=0;entryDy=0;" parent="1" source="49" target="46" edge="1">
|
||||
<mxGeometry relative="1" as="geometry">
|
||||
<Array as="points">
|
||||
<mxPoint x="680" y="980"/>
|
||||
<mxPoint x="680" y="210"/>
|
||||
</Array>
|
||||
</mxGeometry>
|
||||
</mxCell>
|
||||
<mxCell id="52" value="yes" style="edgeStyle=none;html=1;" edge="1" parent="1" source="49" target="51">
|
||||
<mxGeometry relative="1" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="49" value="End of message ?" style="rhombus;whiteSpace=wrap;html=1;" parent="1" vertex="1">
|
||||
<mxGeometry x="320" y="940" width="80" height="80" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="53" value="" style="edgeStyle=none;html=1;" edge="1" parent="1" source="51" target="34">
|
||||
<mxGeometry relative="1" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="51" value="Perform dictionary<br>lookup, get score" style="whiteSpace=wrap;html=1;" vertex="1" parent="1">
|
||||
<mxGeometry x="300" y="1060" width="120" height="60" as="geometry"/>
|
||||
</mxCell>
|
||||
</root>
|
||||
</mxGraphModel>
|
||||
</diagram>
|
||||
</mxfile>
|
93
phase1-fix/deliver/diagram/letter_statistics.drawio
Normal file
93
phase1-fix/deliver/diagram/letter_statistics.drawio
Normal file
@@ -0,0 +1,93 @@
|
||||
<mxfile host="65bd71144e">
|
||||
<diagram id="jUaFL9_61w-NF607VE0Q" name="Page-1">
|
||||
<mxGraphModel dx="992" dy="803" 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<br>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;" parent="1" source="49" target="59" edge="1">
|
||||
<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;" parent="1" source="52" target="59" edge="1">
|
||||
<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;" parent="1" vertex="1">
|
||||
<mxGeometry x="260" y="320" width="120" height="60" as="geometry"/>
|
||||
</mxCell>
|
||||
</root>
|
||||
</mxGraphModel>
|
||||
</diagram>
|
||||
</mxfile>
|
BIN
phase1-fix/deliver/diagram/letter_statistics.png
(Stored with Git LFS)
Normal file
BIN
phase1-fix/deliver/diagram/letter_statistics.png
(Stored with Git LFS)
Normal file
Binary file not shown.
90
phase1-fix/deliver/diagram/system_flow.drawio
Normal file
90
phase1-fix/deliver/diagram/system_flow.drawio
Normal file
@@ -0,0 +1,90 @@
|
||||
<mxfile host="65bd71144e">
|
||||
<diagram id="uDbKBpJxGqoVXxld_zHr" name="Page-1">
|
||||
<mxGraphModel dx="1027" dy="669" 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" value="" style="edgeStyle=none;html=1;" parent="1" source="2" target="5" edge="1">
|
||||
<mxGeometry relative="1" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="2" value="select option<br>( 1 / 2 / q ) ?<br><br>1: encrypt<br>2: decrypt<br>q; quit" style="whiteSpace=wrap;html=1;movable=1;resizable=1;rotatable=1;deletable=1;editable=1;connectable=1;" parent="1" vertex="1">
|
||||
<mxGeometry x="355" y="140" width="120" height="120" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="9" value="No" style="edgeStyle=none;html=1;" parent="1" source="5" target="8" edge="1">
|
||||
<mxGeometry relative="1" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="21" value="Yes" style="edgeStyle=none;html=1;" parent="1" source="5" target="20" edge="1">
|
||||
<mxGeometry relative="1" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="5" value="selected&nbsp;<br>1 ?" style="rhombus;whiteSpace=wrap;html=1;" parent="1" vertex="1">
|
||||
<mxGeometry x="375" y="300" width="80" height="80" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="11" value="No" style="edgeStyle=none;html=1;" parent="1" source="8" target="10" edge="1">
|
||||
<mxGeometry relative="1" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="23" value="Yes" style="edgeStyle=none;html=1;" parent="1" source="8" target="22" edge="1">
|
||||
<mxGeometry relative="1" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="8" value="selected&nbsp;<br>2 ?" style="rhombus;whiteSpace=wrap;html=1;" parent="1" vertex="1">
|
||||
<mxGeometry x="375" y="460" width="80" height="80" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="18" value="Yes" style="edgeStyle=none;html=1;" parent="1" source="10" target="16" edge="1">
|
||||
<mxGeometry relative="1" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="29" value="" style="edgeStyle=none;html=1;" parent="1" source="10" target="28" edge="1">
|
||||
<mxGeometry relative="1" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="10" value="selected&nbsp;<br>q ?" style="rhombus;whiteSpace=wrap;html=1;" parent="1" vertex="1">
|
||||
<mxGeometry x="375" y="620" width="80" height="80" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="14" value="" style="edgeStyle=none;html=1;" parent="1" source="13" target="2" edge="1">
|
||||
<mxGeometry relative="1" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="13" value="Start" style="ellipse;whiteSpace=wrap;html=1;rounded=1;strokeColor=default;" parent="1" vertex="1">
|
||||
<mxGeometry x="355" y="50" width="120" height="40" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="16" value="End" style="ellipse;whiteSpace=wrap;html=1;rounded=1;strokeColor=default;" parent="1" vertex="1">
|
||||
<mxGeometry x="355" y="730" width="120" height="40" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="24" style="edgeStyle=none;html=1;exitX=0;exitY=0.5;exitDx=0;exitDy=0;entryX=-0.007;entryY=0.768;entryDx=0;entryDy=0;entryPerimeter=0;" parent="1" source="20" target="2" edge="1">
|
||||
<mxGeometry relative="1" as="geometry">
|
||||
<mxPoint x="350" y="216" as="targetPoint"/>
|
||||
<Array as="points">
|
||||
<mxPoint x="150" y="340"/>
|
||||
<mxPoint x="150" y="232"/>
|
||||
</Array>
|
||||
</mxGeometry>
|
||||
</mxCell>
|
||||
<mxCell id="20" value="encrypt file" style="whiteSpace=wrap;html=1;movable=1;resizable=1;rotatable=1;deletable=1;editable=1;connectable=1;" parent="1" vertex="1">
|
||||
<mxGeometry x="190" y="310" width="120" height="60" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="22" value="decrypt file" style="whiteSpace=wrap;html=1;movable=1;resizable=1;rotatable=1;deletable=1;editable=1;connectable=1;" parent="1" vertex="1">
|
||||
<mxGeometry x="190" y="470" width="120" height="60" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="26" style="edgeStyle=none;html=1;exitX=0;exitY=0.5;exitDx=0;exitDy=0;entryX=0;entryY=0.5;entryDx=0;entryDy=0;" parent="1" source="22" target="2" edge="1">
|
||||
<mxGeometry relative="1" as="geometry">
|
||||
<mxPoint x="200" y="350" as="sourcePoint"/>
|
||||
<mxPoint x="350" y="200" as="targetPoint"/>
|
||||
<Array as="points">
|
||||
<mxPoint x="130" y="500"/>
|
||||
<mxPoint x="130" y="200"/>
|
||||
</Array>
|
||||
</mxGeometry>
|
||||
</mxCell>
|
||||
<mxCell id="28" value="Show user error message" style="whiteSpace=wrap;html=1;movable=1;resizable=1;rotatable=1;deletable=1;editable=1;connectable=1;" parent="1" vertex="1">
|
||||
<mxGeometry x="190" y="630" width="120" height="60" as="geometry"/>
|
||||
</mxCell>
|
||||
<mxCell id="30" style="edgeStyle=none;html=1;exitX=0;exitY=0.5;exitDx=0;exitDy=0;entryX=-0.009;entryY=0.167;entryDx=0;entryDy=0;entryPerimeter=0;" parent="1" source="28" target="2" edge="1">
|
||||
<mxGeometry relative="1" as="geometry">
|
||||
<mxPoint x="200" y="510" as="sourcePoint"/>
|
||||
<mxPoint x="350" y="180" as="targetPoint"/>
|
||||
<Array as="points">
|
||||
<mxPoint x="120" y="660"/>
|
||||
<mxPoint x="120" y="160"/>
|
||||
</Array>
|
||||
</mxGeometry>
|
||||
</mxCell>
|
||||
</root>
|
||||
</mxGraphModel>
|
||||
</diagram>
|
||||
</mxfile>
|
BIN
phase1-fix/deliver/diagram/system_flow.png
(Stored with Git LFS)
Normal file
BIN
phase1-fix/deliver/diagram/system_flow.png
(Stored with Git LFS)
Normal file
Binary file not shown.
1
phase1-fix/deliver/people_e.txt
Normal file
1
phase1-fix/deliver/people_e.txt
Normal file
@@ -0,0 +1 @@
|
||||
BQABXQ BQABXQ BQABXQ
|
@@ -0,0 +1,19 @@
|
||||
1.如果淨係放嗰個txt file佢唔識encrypt 後output 個encrypt後嘅document .即係我如果delete咗wiki_e.txt佢唔識自己再output。需要人手開一個新txt document
|
||||
|
||||
詳情可以睇 Problem1.mp4
|
||||
|
||||
2. 1.如果篇文有兩個相同(無論係相同或者多過)字數嘅Alphabet 出現 呢個時候個program就會encrypt錯。例如將「people 」呢隻字打到200字 「P」同「E」嘅數量係一樣
|
||||
所以encrypt完之後變出嚟嘅亂碼 再decrypt唔會變返「People」所以要搵解決方法做到點樣先可以知道decrypt gen出嚟嘅key(k)係準確。
|
||||
|
||||
詳情可以睇Problem2 (Alphabet E is the same with P).mp4 Problem 2( Alphabet P is more than E and the guess of Key is error).mp4
|
||||
|
||||
阿sir指定話要將呢個problem寫入report睇下點樣solve同埋點解會出現呢個情況. Thanks very much
|
||||
|
||||
|
||||
3.個Guildline要求無論係Uppercase定LowerCase都要直接將佢變成Uppercase但係只有文字轉Uppercase標點符號同埋spaces唔會改變。
|
||||
|
||||
即係gen出嚟嘅亂碼會係全大階。 (咁係唔係即係delete咗Lowercase段code就得?)
|
||||
|
||||
4.要加多個flow chart喺report入面係整合曬成個program.
|
||||
|
||||
Thanks a lot for helping me.!!!!!!
|
196
phase1-fix/deliver/problem1/shift_cipher_encrypter.py
Normal file
196
phase1-fix/deliver/problem1/shift_cipher_encrypter.py
Normal 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',encoding="utf-8") as fi:
|
||||
temp = ''.join(fi.readlines())
|
||||
|
||||
# open target file (encrypted text)
|
||||
with open(output_file,'a+') 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...")
|
5
phase1-fix/deliver/problem1/test.sh
Normal file
5
phase1-fix/deliver/problem1/test.sh
Normal file
@@ -0,0 +1,5 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
set -ex
|
||||
|
||||
python ./shift_cipher_encrypter.py
|
8
phase1-fix/deliver/problem1/wiki.txt
Normal file
8
phase1-fix/deliver/problem1/wiki.txt
Normal 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 1841–1842. 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
|
8
phase1-fix/deliver/problem1/wiki_e.txt
Normal file
8
phase1-fix/deliver/problem1/wiki_e.txt
Normal file
@@ -0,0 +1,8 @@
|
||||
Sfg: iuuqt://fo.xjljqfejb.psh/xjlj/Ipoh_Lpoh
|
||||
|
||||
|
||||
Ipoh Lpoh xbt ftubcmjtife bt b dpmpoz pg uif Csjujti Fnqjsf bgufs uif Rjoh Fnqjsf dfefe Ipoh Lpoh Jtmboe jo 1841–1842. Uif dpmpoz fyqboefe up uif Lpxmppo Qfojotvmb jo 1860 boe xbt gvsuifs fyufoefe xifo uif Vojufe Ljohepn pcubjofe b 99-zfbs mfbtf pg uif Ofx Ufssjupsjft jo 1898. Ipoh Lpoh xbt csjfgmz pddvqjfe cz Kbqbo gspn 1941 up 1945 evsjoh Xpsme Xbs JJ. Uif xipmf ufssjupsz xbt usbotgfssfe gspn uif Vojufe Ljohepn up Dijob jo 1997. Ipoh Lpoh nbjoubjot tfqbsbuf hpwfsojoh boe fdpopnjd tztufnt gspn uibu pg nbjomboe Dijob voefs uif qsjodjqmf pg "pof dpvousz, uxp tztufnt".[g]
|
||||
Psjhjobmmz b tqbstfmz qpqvmbufe bsfb pg gbsnjoh boe gjtijoh wjmmbhft,[18][19] uif ufssjupsz jt opx pof pg uif xpsme't nptu tjhojgjdbou gjobodjbm dfousft boe dpnnfsdjbm qpsut. Ipoh Lpoh jt uif xpsme't gpvsui-sbolfe hmpcbm gjobodjbm dfousf, ojoui-mbshftu fyqpsufs, boe fjhiui-mbshftu jnqpsufs. Jut dvssfodz, uif Ipoh Lpoh epmmbs, jt uif fjhiui nptu usbefe dvssfodz jo uif xpsme. Ipnf up uif tfdpoe-ijhiftu ovncfs pg cjmmjpobjsft pg boz djuz jo uif xpsme, Ipoh Lpoh ibt uif mbshftu dpodfousbujpo pg vmusb ijhi-ofu-xpsui joejwjevbmt. Bmuipvhi uif djuz ibt pof pg uif ijhiftu qfs dbqjub jodpnft jo uif xpsme, tfwfsf jodpnf jofrvbmjuz fyjtut bnpoh uif qpqvmbujpo. Eftqjuf ibwjoh uif mbshftu ovncfs pg tlztdsbqfst pg boz djuz jo uif xpsme, ipvtjoh jo Ipoh Lpoh ibt cffo xfmm-epdvnfoufe up fyqfsjfodf b dispojd qfstjtufou tipsubhf.
|
||||
Ipoh Lpoh jt b ijhimz efwfmpqfe ufssjupsz boe ibt b Ivnbo Efwfmpqnfou Joefy (IEJ) pg 0.952, sboljoh gpvsui jo uif xpsme. Uif djuz ibt uif tfdpoe ijhiftu mjgf fyqfdubodz jo uif xpsme, boe b qvcmjd usbotqpsu sbuf fydffejoh 90%.
|
||||
|
||||
bspvoe 261 xpset
|
1
phase1-fix/deliver/problem2/aaaaa.txt
Normal file
1
phase1-fix/deliver/problem2/aaaaa.txt
Normal file
@@ -0,0 +1 @@
|
||||
aaaaa
|
1
phase1-fix/deliver/problem2/apple.txt
Normal file
1
phase1-fix/deliver/problem2/apple.txt
Normal file
@@ -0,0 +1 @@
|
||||
apple apple apple apple apple apple apple apple apple apple apple apple apple apple apple apple apple apple apple apple apple apple apple apple apple apple apple apple apple apple apple apple apple apple apple apple
|
1
phase1-fix/deliver/problem2/apple_e.txt
Normal file
1
phase1-fix/deliver/problem2/apple_e.txt
Normal file
@@ -0,0 +1 @@
|
||||
ETTPI ETTPI ETTPI
|
1
phase1-fix/deliver/problem2/people.txt
Normal file
1
phase1-fix/deliver/problem2/people.txt
Normal file
@@ -0,0 +1 @@
|
||||
people people people
|
1
phase1-fix/deliver/problem2/people_e.txt
Normal file
1
phase1-fix/deliver/problem2/people_e.txt
Normal file
@@ -0,0 +1 @@
|
||||
BQABXQ BQABXQ BQABXQ
|
293
phase1-fix/deliver/problem2/shift_cipher_encrypter.py
Normal file
293
phase1-fix/deliver/problem2/shift_cipher_encrypter.py
Normal file
@@ -0,0 +1,293 @@
|
||||
#!/usr/bin/env python
|
||||
import os,sys
|
||||
|
||||
ORD_a = ord('a') # 97
|
||||
ORD_A = ord('A') # 65
|
||||
|
||||
DICTIONARY = []
|
||||
|
||||
def shift_cipher_encrypt(plaintext, key):
|
||||
# apply encryption to text with given key
|
||||
encrypted_message = ''
|
||||
|
||||
for char in plaintext:
|
||||
if char.isalpha():
|
||||
char = char.upper()
|
||||
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',encoding="utf-8") as fi:
|
||||
temp = ''.join(fi.readlines())
|
||||
|
||||
# open target file (encrypted text)
|
||||
with open(output_file,'w+') 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, dictionary):
|
||||
# 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)
|
||||
|
||||
decrypted = False
|
||||
done = False
|
||||
decrypted_text = ''
|
||||
|
||||
print("try decrypt by guessing maximum occurrence ... ")
|
||||
[valid, text] = decrypt_by_guessed_k(e_temp, dictionary)
|
||||
decrypted = valid
|
||||
decrypted_text = text
|
||||
|
||||
if not(decrypted):
|
||||
print("decrypt by guessing maximum occurence seems doesn't work...")
|
||||
[valid, text]=decrypt_by_bruce_force_k(e_temp, dictionary)
|
||||
decrypted = valid
|
||||
decrypted_text = text
|
||||
|
||||
if (decrypted):
|
||||
print()
|
||||
print("Final decrypted message:")
|
||||
print()
|
||||
print(decrypted_text)
|
||||
print()
|
||||
|
||||
else:
|
||||
print("Seems neither of them works.")
|
||||
|
||||
|
||||
def decrypt_by_guessed_k(e_temp, dictionary):
|
||||
print('decrypted by guessed k')
|
||||
characters_distribution = count_most_occurrence_letter(e_temp)
|
||||
|
||||
print('')
|
||||
print('distribution of letters in encrypted text (case insensitive, from a to z)')
|
||||
print([chr(65+i) for i in range(0,26)])
|
||||
print(['{:0>1}'.format(i) for i in characters_distribution])
|
||||
|
||||
print('')
|
||||
guess_k = find_max_occurrence(characters_distribution)
|
||||
print(f'try decrypt using guess_k -> guessed k: {guess_k}')
|
||||
|
||||
decrypted_text = shift_cipher_decrypt(e_temp, guess_k)
|
||||
list_texts = decrypted_text.split(' ')
|
||||
check_result_using_guess_k = check_words_valid(list_texts, dictionary, 0.8)
|
||||
|
||||
|
||||
|
||||
return [check_result_using_guess_k, decrypted_text]
|
||||
|
||||
def decrypt_by_bruce_force_k(e_temp, dictionary):
|
||||
print()
|
||||
print('try decrypt by bruce forcing k ...')
|
||||
# will open an encrypted file and decrypt it by a guessed key
|
||||
dictionary_match_found = False
|
||||
characters_distribution = count_most_occurrence_letter(e_temp)
|
||||
guess_k = bruce_force_k(characters_distribution, e_temp, dictionary)
|
||||
decrypted_text = shift_cipher_decrypt(e_temp, guess_k)
|
||||
|
||||
return [True, decrypted_text]
|
||||
|
||||
def check_words_valid(list_decrypted_text,dictionary, passing_gate):
|
||||
result = list(map(lambda x: dictionary_lookup(x, dictionary), list_decrypted_text))
|
||||
len_all_result = len(result)
|
||||
true_in_result = len(list(filter(lambda r: r, result)))
|
||||
|
||||
return true_in_result/len_all_result > passing_gate
|
||||
|
||||
def bruce_force_k(characters_distribution, e_temp, dictionary):
|
||||
output = -1
|
||||
done = False
|
||||
|
||||
shifted_character_distribution = characters_distribution[4:]+characters_distribution[0:4]
|
||||
# print(shifted_character_distribution)
|
||||
|
||||
for (k) in range(0,26):
|
||||
|
||||
if (shifted_character_distribution[k] > 0):
|
||||
guess_k = k
|
||||
|
||||
decrypted_text = shift_cipher_decrypt(e_temp, guess_k)
|
||||
list_decrypted_text = decrypted_text.split(' ')
|
||||
result = check_words_valid(list_decrypted_text, dictionary, 0.8)
|
||||
print(f'trying k={guess_k} -> result "{decrypted_text}"')
|
||||
|
||||
if result == True:
|
||||
print('guessed k matching:', guess_k)
|
||||
output = guess_k
|
||||
break
|
||||
else:
|
||||
# NOTE: for debug
|
||||
# print(f'skip bruce because k={k} is not possible')
|
||||
pass
|
||||
|
||||
return output
|
||||
|
||||
|
||||
def dictionary_lookup(text_to_lookup, dictionary):
|
||||
try:
|
||||
return dictionary.index(text_to_lookup.upper()) > -1
|
||||
except:
|
||||
return False
|
||||
|
||||
def load_dictionary():
|
||||
output = []
|
||||
with open('./words.txt','r',encoding="utf-8") as f_dict:
|
||||
output = f_dict.readlines()
|
||||
output = list(map(lambda x: x.strip(), output))
|
||||
output = list(map(lambda x: x.upper(), output))
|
||||
|
||||
return output
|
||||
|
||||
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, load_dictionary())
|
||||
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...")
|
5
phase1-fix/deliver/problem2/test.sh
Normal file
5
phase1-fix/deliver/problem2/test.sh
Normal file
@@ -0,0 +1,5 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
set -ex
|
||||
|
||||
python ./shift_cipher_encrypter.py
|
8
phase1-fix/deliver/problem2/wiki.txt
Normal file
8
phase1-fix/deliver/problem2/wiki.txt
Normal 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 1841–1842. 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
|
8
phase1-fix/deliver/problem2/wiki_e.txt
Normal file
8
phase1-fix/deliver/problem2/wiki_e.txt
Normal file
@@ -0,0 +1,8 @@
|
||||
Dqr: tffbe://qz.iuwubqpum.ads/iuwu/Tazs_Wazs
|
||||
|
||||
|
||||
Tazs Wazs ime qefmnxuetqp me m oaxazk ar ftq Ndufuet Qybudq mrfqd ftq Cuzs Qybudq oqpqp Tazs Wazs Uexmzp uz 1841V1842. Ftq oaxazk qjbmzpqp fa ftq Waixaaz Bqzuzegxm uz 1860 mzp ime rgdftqd qjfqzpqp itqz ftq Gzufqp Wuzspay anfmuzqp m 99-kqmd xqmeq ar ftq Zqi Fqddufaduqe uz 1898. Tazs Wazs ime nduqrxk aoogbuqp nk Vmbmz rday 1941 fa 1945 pgduzs Iadxp Imd UU. Ftq itaxq fqddufadk ime fdmzerqddqp rday ftq Gzufqp Wuzspay fa Otuzm uz 1997. Tazs Wazs ymuzfmuze eqbmdmfq sahqdzuzs mzp qoazayuo ekefqye rday ftmf ar ymuzxmzp Otuzm gzpqd ftq bduzoubxq ar "azq oagzfdk, fia ekefqye".[r]
|
||||
Adusuzmxxk m ebmdeqxk babgxmfqp mdqm ar rmdyuzs mzp ruetuzs huxxmsqe,[18][19] ftq fqddufadk ue zai azq ar ftq iadxp'e yaef euszuruomzf ruzmzoumx oqzfdqe mzp oayyqdoumx badfe. Tazs Wazs ue ftq iadxp'e ragdft-dmzwqp sxanmx ruzmzoumx oqzfdq, zuzft-xmdsqef qjbadfqd, mzp qustft-xmdsqef uybadfqd. Ufe ogddqzok, ftq Tazs Wazs paxxmd, ue ftq qustft yaef fdmpqp ogddqzok uz ftq iadxp. Tayq fa ftq eqoazp-tustqef zgynqd ar nuxxuazmudqe ar mzk oufk uz ftq iadxp, Tazs Wazs tme ftq xmdsqef oazoqzfdmfuaz ar gxfdm tust-zqf-iadft uzpuhupgmxe. Mxftagst ftq oufk tme azq ar ftq tustqef bqd ombufm uzoayqe uz ftq iadxp, eqhqdq uzoayq uzqcgmxufk qjuefe myazs ftq babgxmfuaz. Pqebufq tmhuzs ftq xmdsqef zgynqd ar ewkeodmbqde ar mzk oufk uz ftq iadxp, tageuzs uz Tazs Wazs tme nqqz iqxx-paogyqzfqp fa qjbqduqzoq m otdazuo bqdeuefqzf etadfmsq.
|
||||
Tazs Wazs ue m tustxk pqhqxabqp fqddufadk mzp tme m Tgymz Pqhqxabyqzf Uzpqj (TPU) ar 0.952, dmzwuzs ragdft uz ftq iadxp. Ftq oufk tme ftq eqoazp tustqef xurq qjbqofmzok uz ftq iadxp, mzp m bgnxuo fdmzebadf dmfq qjoqqpuzs 90%.
|
||||
|
||||
mdagzp 261 iadpe
|
466550
phase1-fix/deliver/problem2/words.txt
Normal file
466550
phase1-fix/deliver/problem2/words.txt
Normal file
File diff suppressed because it is too large
Load Diff
1
phase1-fix/deliver/problem2/zzzzz.txt
Normal file
1
phase1-fix/deliver/problem2/zzzzz.txt
Normal file
@@ -0,0 +1 @@
|
||||
zzzzz
|
144
phase1-fix/deliver/problem3/shift_cipher_encrypter.py
Normal file
144
phase1-fix/deliver/problem3/shift_cipher_encrypter.py
Normal file
@@ -0,0 +1,144 @@
|
||||
#!/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():
|
||||
char = char.upper()
|
||||
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',encoding="utf-8") as fi:
|
||||
temp = ''.join(fi.readlines())
|
||||
|
||||
# open target file (encrypted text)
|
||||
with open(output_file,'w+') 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)
|
||||
|
||||
temp = encrypt_file('./wiki.txt', 8)
|
||||
# with open('./wiki_e.txt','w+') as fo:
|
||||
# fo.writelines([temp])
|
||||
|
||||
print("Exiting...")
|
5
phase1-fix/deliver/problem3/test.sh
Normal file
5
phase1-fix/deliver/problem3/test.sh
Normal file
@@ -0,0 +1,5 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
set -ex
|
||||
|
||||
python ./shift_cipher_encrypter.py
|
8
phase1-fix/deliver/problem3/wiki.txt
Normal file
8
phase1-fix/deliver/problem3/wiki.txt
Normal 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 1841–1842. 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
|
8
phase1-fix/deliver/problem3/wiki_e.txt
Normal file
8
phase1-fix/deliver/problem3/wiki_e.txt
Normal file
@@ -0,0 +1,8 @@
|
||||
ZMN: PBBXA://MV.EQSQXMLQI.WZO/EQSQ/PWVO_SWVO
|
||||
|
||||
|
||||
PWVO SWVO EIA MABIJTQAPML IA I KWTWVG WN BPM JZQBQAP MUXQZM INBMZ BPM YQVO MUXQZM KMLML PWVO SWVO QATIVL QV 1841–1842. BPM KWTWVG MFXIVLML BW BPM SWETWWV XMVQVACTI QV 1860 IVL EIA NCZBPMZ MFBMVLML EPMV BPM CVQBML SQVOLWU WJBIQVML I 99-GMIZ TMIAM WN BPM VME BMZZQBWZQMA QV 1898. PWVO SWVO EIA JZQMNTG WKKCXQML JG RIXIV NZWU 1941 BW 1945 LCZQVO EWZTL EIZ QQ. BPM EPWTM BMZZQBWZG EIA BZIVANMZZML NZWU BPM CVQBML SQVOLWU BW KPQVI QV 1997. PWVO SWVO UIQVBIQVA AMXIZIBM OWDMZVQVO IVL MKWVWUQK AGABMUA NZWU BPIB WN UIQVTIVL KPQVI CVLMZ BPM XZQVKQXTM WN "WVM KWCVBZG, BEW AGABMUA".[N]
|
||||
WZQOQVITTG I AXIZAMTG XWXCTIBML IZMI WN NIZUQVO IVL NQAPQVO DQTTIOMA,[18][19] BPM BMZZQBWZG QA VWE WVM WN BPM EWZTL'A UWAB AQOVQNQKIVB NQVIVKQIT KMVBZMA IVL KWUUMZKQIT XWZBA. PWVO SWVO QA BPM EWZTL'A NWCZBP-ZIVSML OTWJIT NQVIVKQIT KMVBZM, VQVBP-TIZOMAB MFXWZBMZ, IVL MQOPBP-TIZOMAB QUXWZBMZ. QBA KCZZMVKG, BPM PWVO SWVO LWTTIZ, QA BPM MQOPBP UWAB BZILML KCZZMVKG QV BPM EWZTL. PWUM BW BPM AMKWVL-PQOPMAB VCUJMZ WN JQTTQWVIQZMA WN IVG KQBG QV BPM EWZTL, PWVO SWVO PIA BPM TIZOMAB KWVKMVBZIBQWV WN CTBZI PQOP-VMB-EWZBP QVLQDQLCITA. ITBPWCOP BPM KQBG PIA WVM WN BPM PQOPMAB XMZ KIXQBI QVKWUMA QV BPM EWZTL, AMDMZM QVKWUM QVMYCITQBG MFQABA IUWVO BPM XWXCTIBQWV. LMAXQBM PIDQVO BPM TIZOMAB VCUJMZ WN ASGAKZIXMZA WN IVG KQBG QV BPM EWZTL, PWCAQVO QV PWVO SWVO PIA JMMV EMTT-LWKCUMVBML BW MFXMZQMVKM I KPZWVQK XMZAQABMVB APWZBIOM.
|
||||
PWVO SWVO QA I PQOPTG LMDMTWXML BMZZQBWZG IVL PIA I PCUIV LMDMTWXUMVB QVLMF (PLQ) WN 0.952, ZIVSQVO NWCZBP QV BPM EWZTL. BPM KQBG PIA BPM AMKWVL PQOPMAB TQNM MFXMKBIVKG QV BPM EWZTL, IVL I XCJTQK BZIVAXWZB ZIBM MFKMMLQVO 90%.
|
||||
|
||||
IZWCVL 261 EWZLA
|
BIN
phase1-fix/deliver/sc/decryption_demo.png
(Stored with Git LFS)
Normal file
BIN
phase1-fix/deliver/sc/decryption_demo.png
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
phase1-fix/deliver/sc/encryption_step1.png
(Stored with Git LFS)
Normal file
BIN
phase1-fix/deliver/sc/encryption_step1.png
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
phase1-fix/deliver/sc/encryption_step2.png
(Stored with Git LFS)
Normal file
BIN
phase1-fix/deliver/sc/encryption_step2.png
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
phase1-fix/deliver/sc/home.png
(Stored with Git LFS)
Normal file
BIN
phase1-fix/deliver/sc/home.png
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
phase1-fix/deliver/sc/message_len_short_demo.png
(Stored with Git LFS)
Normal file
BIN
phase1-fix/deliver/sc/message_len_short_demo.png
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
phase1-fix/deliver/sc/quit_demo.png
(Stored with Git LFS)
Normal file
BIN
phase1-fix/deliver/sc/quit_demo.png
(Stored with Git LFS)
Normal file
Binary file not shown.
328
phase1-fix/deliver/shift_cipher_encrypter.py
Normal file
328
phase1-fix/deliver/shift_cipher_encrypter.py
Normal file
@@ -0,0 +1,328 @@
|
||||
#!/usr/bin/env python
|
||||
import os
|
||||
import 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():
|
||||
# change every character to upper case before enter to the loop to
|
||||
# compare. (requirement)
|
||||
char = char.upper()
|
||||
# Determine ASCII offset based on uppercase or lowercase letter
|
||||
ascii_offset = ORD_A
|
||||
|
||||
# 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(cipher_text, key):
|
||||
# decrypt the text using k as key
|
||||
|
||||
plaintext = ""
|
||||
|
||||
for char in cipher_text:
|
||||
if char.isalpha():
|
||||
# Determine ASCII offset based on lowercase or uppercase letter
|
||||
ascii_offset = ORD_A
|
||||
|
||||
# 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_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.upper()) - 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):
|
||||
# encrypt file given by file_path with key
|
||||
|
||||
# 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', encoding="utf-8") as fi:
|
||||
temp = ''.join(fi.readlines())
|
||||
|
||||
# open target file (encrypted text), to be able to create file if not
|
||||
# exist
|
||||
with open(output_file, 'w+') 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, dictionary):
|
||||
# will open an encrypted file and decrypt it by a guessed key
|
||||
#
|
||||
# try to guess the k by e(as specified) first
|
||||
# PASS: show user decrypted
|
||||
# FAIL: process below
|
||||
# try to bruce force the k by all possible k's candiates
|
||||
# PASS: show user decrypted
|
||||
# FAIL: show user cannot decrypt message
|
||||
|
||||
with open(file_path, 'r') as fi:
|
||||
# beginning of the process
|
||||
# read file and join the lines all
|
||||
lines = fi.readlines()
|
||||
encrypted_text = ''.join(lines)
|
||||
|
||||
decrypted = False
|
||||
done = False
|
||||
decrypted_text = ''
|
||||
|
||||
print("try decrypt by guessing maximum occurrence ... ")
|
||||
[valid, text] = decrypt_by_letter_occurrence(encrypted_text, dictionary)
|
||||
decrypted = valid
|
||||
decrypted_text = text
|
||||
|
||||
# if the message cannot decrypt by letter e population
|
||||
if not (decrypted):
|
||||
print("decrypt by guessing maximum occurence seems doesn't work...")
|
||||
[valid, text] = decrypt_by_bruce_force(encrypted_text, dictionary)
|
||||
decrypted = valid
|
||||
decrypted_text = text
|
||||
|
||||
if (decrypted):
|
||||
print()
|
||||
print("Final decrypted message:")
|
||||
print()
|
||||
print(decrypted_text)
|
||||
print()
|
||||
|
||||
else:
|
||||
# no decryption works
|
||||
print("Seems neither of them works.")
|
||||
|
||||
|
||||
def decrypt_by_letter_occurrence(enc_text, dictionary):
|
||||
# 1. get the occurrence/population of letter from whole encrypted message
|
||||
# 2. find the max occurrence
|
||||
# 3. find the distance between max letter and letter "E" (denoted: "guessed k")
|
||||
# 4. try decrypt using "guessed k"
|
||||
# 5. lookup in dictionary (check_words_valid) and check if the decrypted valid.
|
||||
|
||||
print('decrypted by guessed k')
|
||||
characters_population = count_most_occurrence_letter(enc_text)
|
||||
|
||||
print('')
|
||||
print('population of letters in encrypted text (case insensitive, from a to z)')
|
||||
print([chr(65 + i) for i in range(0, 26)])
|
||||
print(['{:0>1}'.format(i) for i in characters_population])
|
||||
|
||||
print('')
|
||||
guess_k = find_max_occurrence(characters_population)
|
||||
print(f'try decrypt using guess_k -> guessed k: {guess_k}')
|
||||
|
||||
decrypted_text = shift_cipher_decrypt(enc_text, guess_k)
|
||||
list_texts = decrypted_text.split(' ')
|
||||
check_result_using_guess_k = check_words_valid(list_texts, dictionary, 0.8)
|
||||
|
||||
return [check_result_using_guess_k, decrypted_text]
|
||||
|
||||
|
||||
def decrypt_by_bruce_force(encrypted_text, dictionary):
|
||||
# 1. get the occurrence/population of letter from whole encrypted message
|
||||
# 2. find the candidates of k (filter all zero answer in step 1)
|
||||
|
||||
# 3. find the distance between max letter and letter "E" -> "guessed k"
|
||||
# 4. try decrypt using this "guessed k"
|
||||
# 5. lookup in dictionary (check_words_valid) and check if the decrypted valid.
|
||||
|
||||
print()
|
||||
print('try decrypt by bruce forcing k ...')
|
||||
# will open an encrypted file and decrypt it by a guessed key
|
||||
dictionary_match_found = False
|
||||
characters_population = count_most_occurrence_letter(encrypted_text)
|
||||
|
||||
guess_k = bruce_force_k(characters_population, encrypted_text, dictionary)
|
||||
# guess_k == -1 means the decrypted message failed in dictionary lookup,
|
||||
# send the result directly
|
||||
if (guess_k == -999):
|
||||
return [False, '']
|
||||
|
||||
decrypted_text = shift_cipher_decrypt(encrypted_text, guess_k)
|
||||
check_result_using_guess_k = check_words_valid(decrypted_text, dictionary, 0.8)
|
||||
|
||||
return [check_result_using_guess_k, decrypted_text]
|
||||
|
||||
|
||||
def check_words_valid(list_decrypted_text, dictionary, passing_gate):
|
||||
# split decrypted text and word-by-word lookup in dictionary
|
||||
# get a score reflect the matching
|
||||
# output true / false when score higher than the passing gate
|
||||
|
||||
result = list(map(lambda x: dictionary_lookup(
|
||||
x, dictionary), list_decrypted_text))
|
||||
len_all_result = len(result)
|
||||
true_in_result = len(list(filter(lambda r: r, result)))
|
||||
|
||||
return true_in_result / len_all_result > passing_gate
|
||||
|
||||
|
||||
def bruce_force_k(characters_population, encrypted_text, dictionary):
|
||||
# 1. shift the character array left by 4 to align E
|
||||
# 2. if the population of
|
||||
|
||||
output = -1
|
||||
done = False
|
||||
|
||||
for (guess_k) in range(0,25+1):
|
||||
|
||||
decrypted_text = shift_cipher_decrypt(encrypted_text, guess_k)
|
||||
list_decrypted_text = decrypted_text.split(' ')
|
||||
result = check_words_valid(list_decrypted_text, dictionary, 0.8)
|
||||
# print(f'trying k={guess_k} -> result "{decrypted_text}"')
|
||||
# print(guess_k, decrypted_text)
|
||||
|
||||
if result:
|
||||
print('guessed k matching:', guess_k)
|
||||
output = guess_k
|
||||
break
|
||||
|
||||
pass
|
||||
|
||||
return output
|
||||
|
||||
|
||||
def dictionary_lookup(text_to_lookup, dictionary):
|
||||
try:
|
||||
return dictionary.index(text_to_lookup.upper()) > -1
|
||||
except BaseException:
|
||||
return False
|
||||
|
||||
|
||||
def load_dictionary():
|
||||
output = []
|
||||
with open('./words.txt', 'r', encoding="utf-8") as f_dict:
|
||||
output = f_dict.readlines()
|
||||
output = list(map(lambda x: x.strip(), output))
|
||||
output = list(map(lambda x: x.upper(), output))
|
||||
|
||||
return output
|
||||
|
||||
# main loop
|
||||
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, load_dictionary())
|
||||
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...")
|
1
phase1-fix/deliver/test.bat
Normal file
1
phase1-fix/deliver/test.bat
Normal file
@@ -0,0 +1 @@
|
||||
python ./shift_cipher_encrypter.py
|
8
phase1-fix/deliver/wiki.txt
Normal file
8
phase1-fix/deliver/wiki.txt
Normal 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 1841–1842. 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
|
8
phase1-fix/deliver/wiki_e.txt
Normal file
8
phase1-fix/deliver/wiki_e.txt
Normal file
@@ -0,0 +1,8 @@
|
||||
KXY: AMMIL://XG.PBDBIXWBT.HKZ/PBDB/AHGZ_DHGZ
|
||||
|
||||
|
||||
AHGZ DHGZ PTL XLMTUEBLAXW TL T VHEHGR HY MAX UKBMBLA XFIBKX TYMXK MAX JBGZ XFIBKX VXWXW AHGZ DHGZ BLETGW BG 1841–1842. MAX VHEHGR XQITGWXW MH MAX DHPEHHG IXGBGLNET BG 1860 TGW PTL YNKMAXK XQMXGWXW PAXG MAX NGBMXW DBGZWHF HUMTBGXW T 99-RXTK EXTLX HY MAX GXP MXKKBMHKBXL BG 1898. AHGZ DHGZ PTL UKBXYER HVVNIBXW UR CTITG YKHF 1941 MH 1945 WNKBGZ PHKEW PTK BB. MAX PAHEX MXKKBMHKR PTL MKTGLYXKKXW YKHF MAX NGBMXW DBGZWHF MH VABGT BG 1997. AHGZ DHGZ FTBGMTBGL LXITKTMX ZHOXKGBGZ TGW XVHGHFBV LRLMXFL YKHF MATM HY FTBGETGW VABGT NGWXK MAX IKBGVBIEX HY "HGX VHNGMKR, MPH LRLMXFL".[Y]
|
||||
HKBZBGTEER T LITKLXER IHINETMXW TKXT HY YTKFBGZ TGW YBLABGZ OBEETZXL,[18][19] MAX MXKKBMHKR BL GHP HGX HY MAX PHKEW'L FHLM LBZGBYBVTGM YBGTGVBTE VXGMKXL TGW VHFFXKVBTE IHKML. AHGZ DHGZ BL MAX PHKEW'L YHNKMA-KTGDXW ZEHUTE YBGTGVBTE VXGMKX, GBGMA-ETKZXLM XQIHKMXK, TGW XBZAMA-ETKZXLM BFIHKMXK. BML VNKKXGVR, MAX AHGZ DHGZ WHEETK, BL MAX XBZAMA FHLM MKTWXW VNKKXGVR BG MAX PHKEW. AHFX MH MAX LXVHGW-ABZAXLM GNFUXK HY UBEEBHGTBKXL HY TGR VBMR BG MAX PHKEW, AHGZ DHGZ ATL MAX ETKZXLM VHGVXGMKTMBHG HY NEMKT ABZA-GXM-PHKMA BGWBOBWNTEL. TEMAHNZA MAX VBMR ATL HGX HY MAX ABZAXLM IXK VTIBMT BGVHFXL BG MAX PHKEW, LXOXKX BGVHFX BGXJNTEBMR XQBLML TFHGZ MAX IHINETMBHG. WXLIBMX ATOBGZ MAX ETKZXLM GNFUXK HY LDRLVKTIXKL HY TGR VBMR BG MAX PHKEW, AHNLBGZ BG AHGZ DHGZ ATL UXXG PXEE-WHVNFXGMXW MH XQIXKBXGVX T VAKHGBV IXKLBLMXGM LAHKMTZX.
|
||||
AHGZ DHGZ BL T ABZAER WXOXEHIXW MXKKBMHKR TGW ATL T ANFTG WXOXEHIFXGM BGWXQ (AWB) HY 0.952, KTGDBGZ YHNKMA BG MAX PHKEW. MAX VBMR ATL MAX LXVHGW ABZAXLM EBYX XQIXVMTGVR BG MAX PHKEW, TGW T INUEBV MKTGLIHKM KTMX XQVXXWBGZ 90%.
|
||||
|
||||
TKHNGW 261 PHKWL
|
466550
phase1-fix/deliver/words.txt
Normal file
466550
phase1-fix/deliver/words.txt
Normal file
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user