-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from HbHbNr/layer3
Layer3
- Loading branch information
Showing
5 changed files
with
72 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
# GNU General Public License Version 3 | ||
|
||
def decrypt(decoded): | ||
# beginning of the text is known, leading to the first bytes of the key | ||
expectedstart = bytearray('==[ Layer 4/6: ', 'utf-8') | ||
xor = bytearray() | ||
|
||
for i in range(len(expectedstart)): | ||
x = expectedstart[i] ^ decoded[i] | ||
xor.append(x) | ||
|
||
# a) 15 * '=' must be in the encrypted text, because the line "==[ Payload ]==" contains 47 * '='. | ||
# b) Multiple occurences are possible, but hopefully in at least one case 17 more '=' will follow. | ||
# c) The last occurence is tried first, because that should be the "Payload"-line. | ||
tattletale = bytearray() | ||
for x in xor: | ||
tattletale.append(x ^ ord('=')) | ||
xorfullstart = decoded.rfind(tattletale) | ||
|
||
# assumption/hope: the next 32 bytes are all encoded '=' | ||
xorfull = bytearray() | ||
for d in decoded[xorfullstart:xorfullstart+32]: | ||
xorfull.append(d ^ ord('=')) | ||
|
||
# decrypt the bytes with the assumed key | ||
decrypted = bytearray() | ||
for i in range(len(decoded)): | ||
decrypted.append(decoded[i] ^ xorfull[i % 32]) | ||
|
||
return decrypted | ||
|
||
|
||
if __name__ == '__main__': | ||
import ascii85 | ||
|
||
payload = ascii85.loadpayload('layers/layer3.txt') | ||
decoded = ascii85.decode(payload) | ||
decoded = decrypt(decoded) | ||
print(decoded.decode()[0:500]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
Example from https://en.wikipedia.org/wiki/Ascii85#Example_for_Ascii85 | ||
|
||
Clear text contains no newlines and reads: | ||
Man is distinguished, not only by his reason, but by this singular passion from other animals, which is a lust of the mind, that by a perseverance of delight in the continued and indefatigable generation of knowledge, exceeds the short vehemence of any carnal pleasure. | ||
|
||
<~9jqo^BlbD-BleB1DJ+*+F(f,q/0JhKF<GL>Cj@.4Gp$d7F!,L7@<6@)/0JDEF<G%<+EV:2F!, | ||
O<DJ+*.@<*K0@<6L(Df-\0Ec5e;DffZ(EZee.Bl.9pF"AGXBPCsi+DGm>@3BB/F*&OCAfu2/AKY | ||
i(DIb:@FD,*)+C]U=@3BN#EcYf8ATD3s@q?d$AftVqCh[NqF<G:8+EV:.+Cf>-FD5W8ARlolDIa | ||
l(DId<j@<?3r@:F%a+D58'ATD4$Bl@l3De:,-DJs`8ARoFb/0JMK@qB4^F!,R<AKZ&-DfTqBG%G | ||
>uD.RTpAKYo'+CT/5+Cei#DII?(E,9)oF*2M7/c~> |