Skip to content

Instantly share code, notes, and snippets.

@fblundun
Last active January 18, 2016 10:23
Show Gist options
  • Save fblundun/ad8d377918260f96eb03 to your computer and use it in GitHub Desktop.
Save fblundun/ad8d377918260f96eb03 to your computer and use it in GitHub Desktop.
List strings which may appear when a target string is base 64-encoded
#!/usr/bin/python
import base64
import sys
input = sys.argv[1]
drop = [0, 2, 3]
def get_combinations(s):
return [(base64.urlsafe_b64encode('a'*i + s)[drop[i]:]).replace('=', '') for i in range(3)]
for x in [get_combinations(sys.argv[1])]:
for y in x:
print(y)
#!/usr/bin/python
import base64
import sys
input = sys.argv[1]
def get_combinations(s):
return [base64.urlsafe_b64encode('a'*i + s)[2*i:-4] for i in range(3)]
for x in [get_combinations(sys.argv[1])]:
for y in x:
print(y)
@fblundun
Copy link
Author

Sample usage:

# Setup: encode "elastic mapreduce" and write it to a file
echo "elastic mapreduce" | base64 > encoded.txt

# search the file for any of a list of strings to which "mapreduce" might be encoded
grep -f <(./single_reverse_base64.py mapreduce) encoded.txt

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment