-
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.
Added whole functionality of the base 64 decoder
- Loading branch information
shourya
committed
Jul 27, 2020
0 parents
commit 6ecc495
Showing
7 changed files
with
1,581 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
ICAgICB8fn5+fn5+fCAgICAgICAgICAgICAgICAgSSB3aWxsIG5vdCBkcmF3IG5ha2VkIGxh | ||
ZGllcyBpbiBjbGFzcy4uLgogICAgIHwgICAgICB8ICAgICAgICAgICAgICAgICAgIEkgd2ls | ||
bCBub3Qgc2thdGVib2FyZCBkb3duIHRoZSBoYWxscy4uLgogICAgIHwgICAgICB8ICAgICAg | ||
IF9fX19fX19fX18gICAgSSB3aWxsIG5vdCBjYWxsIG15IHRlYWNoZXIgIkhvdCBDYWtlcyIu | ||
Li4KICAgICB8IChvKShvKSAgICAgIC8gICAgICAgICAgXCAgICAgSSB3aWxsIG5vdCBpbnN0 | ||
aWdhdGUgcmV2b2x1dGlvbi4uLgogICAgIEAgICAgICBfKSAgX18vIERvbid0IGhhdmUgXCAg | ||
ICBJIHdpbGwgbm90IHdhc3RlIGNoYWxrLi4uCiAgICAgIHwgLF9fX3wgL19fXyAgICBhIGNv | ||
dywgICAgfCAgIEkgZGlkIG5vdCBzZWUgRWx2aXMuLi4KICAgICAgfCAgIC8gICAgICAgXCAg | ||
ICBtYW4hICAgIC8gICAgSSB3aWxsIG5vdCBidXJwIGluIGNsYXNzLi4uCiAgICAgL19fX19c | ||
ICAgICAgICBcX19fX19fX19fXy8gICAgIEdhcmxpYyBndW0gaXMgbm90IGZ1bm55Li4uCiAg | ||
ICAvICAgICAgXCAgICAgICAgICAgICAgICAgICAgICBUaGV5IGFyZSBMYXVnaGluZyBhdCBt | ||
ZSwgbm90IHdpdGggbWUuLi4KICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBUYXIg | ||
aXMgbm90IGEgcGxheXRoaW5nLi4uCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIEkg | ||
d2lsbCBub3QgeWVsbCAiRmlyZSIgaW4gYSBjcm93ZGVkIGNsYXNzcm9vbQo= | ||
|
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,79 @@ | ||
""" | ||
Name: Shourya Raj | ||
Email: [email protected] | ||
""" | ||
|
||
|
||
|
||
class coder: | ||
def __init__(self): | ||
# Initializing the values of the standard Encoded characters | ||
letters = "".join([ | ||
"ABCDEFGHIJKLMNOPQRSTUVWXYZ", | ||
"abcdefghijklmnopqrstuvwxyz", | ||
"0123456789+/", | ||
]) | ||
# ziping in the Dictionary having key as char with the value of range i.e, index number of each characters | ||
self.char2N = dict(zip(letters, range(len(letters)))) | ||
|
||
|
||
def base64Decorder(self, code): | ||
""" | ||
It converts only non-padded value | ||
:param code: There is no need for the parameter it should ask from the terminal | ||
:return: Return the decoded string | ||
""" | ||
|
||
sixBitsLongeach = "" | ||
# check = '' | ||
for char in code: | ||
numericalValue = self.char2N[char] | ||
# {0:b} for the binary format and 06 for the number of the bits | ||
binaryValue = '{0:06b}'.format(numericalValue) | ||
# print(binaryValue) | ||
sixBitsLongeach += str(binaryValue) | ||
# check += str(binaryValue)+'////' | ||
|
||
# print(check) | ||
|
||
#Split into eight bits | ||
eightBitsLongEach = "" | ||
resultOfDecoded = '' | ||
j=0 | ||
left = 0 | ||
right = 8 | ||
# Using two pointers to get the eight bytes and converting into Ascii values | ||
while right <= len(sixBitsLongeach): | ||
# Getting the Eight bytes {Left.......Right (total => 8)} | ||
byte = sixBitsLongeach[left:right] | ||
# Converting the value into int with base of 2 | ||
char = chr(int(byte, 2)) | ||
# adding the Result to the string | ||
resultOfDecoded += char | ||
# Shifting the left pointer at the position of the right pointer | ||
left = right | ||
# Shifting the Right by 8 bytes | ||
right += 8 | ||
|
||
print(resultOfDecoded) | ||
return resultOfDecoded | ||
# print(char2N) | ||
|
||
coder = coder() | ||
stop = False | ||
|
||
while not stop: | ||
print("Enter the Encoded value: ") | ||
code = input() | ||
coder.base64Decorder(code) | ||
if input() == 'end': | ||
stop = True | ||
|
||
# KGl0J3Mp | ||
|
||
# while len(sixBitsLongeach) >= 8: | ||
# # byte = sixBitsLongeach[0:8] | ||
# # char = chr(int(byte, 2)) | ||
# # resultOfDecoded += char | ||
# # sixBitsLongeach = sixBitsLongeach[8:] | ||
# Using Two Pointer |
Oops, something went wrong.