Jul 10, 2018 07:02 PM
(This post was last modified: Jul 10, 2018 07:06 PM by Sparkling Jack.)
Hello guys.
Recently I was needed to make a python script to replace misorderd base64 string to plaint text in a file.
For example:
base64decode(textorder("Wavxmd5V3b=U")) --> iloveyou
original base64 code of "iloveyou" is aWxvdmV5b3U=
Here is the code:
Hope this will be a bit of help for you!
Recently I was needed to make a python script to replace misorderd base64 string to plaint text in a file.
For example:
base64decode(textorder("Wavxmd5V3b=U")) --> iloveyou
original base64 code of "iloveyou" is aWxvdmV5b3U=
Here is the code:
Code
def changeStr(str):
newStr = list(str)
resStr = list(str)
for i in xrange(0,len(newStr),2):
if i==len(newStr)-1:
resStr[i] = newStr[i]
else:
resStr[i]=newStr[i+1]
resStr[i+1] = newStr[i]
str = ''.join(resStr)
return str
def base64Decode(str):
src1=changeStr(str)
result=base64.b64decode(src1)
return result
def find_str(s, char):
index = 0
res = []
if char in s:
c = char[0]
for ch in s:
if ch == c:
if s[index:index+len(char)] == char:
res.append(index+len(char))
index += 1
return res
def find_End(str):
index =0;
if "\"" in str:
for ch in str:
if ch == "\"":
return str[:index]
index+=1
return "None"
if __name__ == '__main__':
infile = open('1.txt')
outputfile = open('2.txt','w')
for line in infile:
pos = find_str(line, "base64decode(textorder(")
if pos:
for i in reversed(pos):
source = find_End(line[i+1:])
result = base64Decode(source)
src = "base64decode(textorder(\""+source+"\"))"
line = line.replace(src, "\""+result+"\"")
outputfile.write(line)

