Validate Base64 using Notepad++
I love fast and flexible software. My love for it will increase exponentially if it is portable or supports such mode, so I can take the application everywhere and run it from anywhere. One of these applications is Notepad++, which I have been using for many years, and for the time being I am not going to switch to something else, even if it also has some disadvantages. The main drawback is that it supports only Windows, but it doesn’t affect me much, since I use Windows as the main OS.
Notepad++ is a free text editor that supports syntax highlighting for many programming languages and files types. It has many features and plugins that allow you to customize the application and automate various tasks. I am not going to describe all the functions of this editor, so I invite you to visit the official website, where you can learn everything about it.
Here I want to talk only about the search function, which is also a powerful feature of the Notepad++. Among other things it supports regular expressions, so you can do a lot of interesting things. For example, it was my faithful assistant while I was developing some tools, when I had to validate many Base64 values and find out why some values cannot be decoded. It turned out that in most cases the values contained invalid characters, so I used Notepad++ to find them. Of course, in this way I just checked for invalid characters, not so that it is a real Base64, but that was what I needed. Now you can use the Repair Tool or Base64 Validator, but I decided to share this method, perhaps it might be useful to you.
To validate Base64 using Notepad++ and find invalid characters:
- Start Notepad++
- Press Ctrl+N to open new tab
- Paste your Base64 value via Ctrl+V
- Open the Find&Replace dialog by pressing Ctrl+F
- Use
[^A-Za-z0-9/+\s]+
as search pattern - Switch “Replace Mode” to “Regular Expression”
- Click the “Find Next” button and analyze your results
The regular expression will find any characters that are not part of the Base64 Alphabet. I did not specify the padding character (equal sign), since it is important to know where the Base64 value ends and it would be useful to find concatenated strings, similar to this one: YWI=YWI=
Of course, you can change the regular expression to suit your needs or tune Notepad++ to make your job easier (for example, you can change highlight color to more easily notice the characters found).
Comments (292)
I hope you enjoy this discussion. In any case, I ask you to join it.
Any suggestions?
def base64Encode(stringtxt):
global base64Encoded
text = str(stringtxt)
itemcount = 0
binarycode = ""
for handle_ascii in (text):
itemcount = itemcount + 1
ascii_code = ord(handle_ascii)
numtohalf = 128
bintxt = ""
for binary in range (0,8):
minustxt = ascii_code - numtohalf
# Checks If Its a 1 or 0.
if minustxt>=0:
ascii_code = minustxt
bintxt = bintxt + "1"
else:
bintxt = bintxt + "0"
numtohalf = numtohalf / 2
binarycode = binarycode + bintxt
if not (len(text)==itemcount):
binarycode = binarycode + ""
binarynum = 0
binarysplited = ""
binarynospace = ""
for b64 in binarycode:
binarysplited = binarysplited + b64
binarynospace = binarynospace + b64
binarynum = binarynum + 1
if binarynum % 6==0 or binarynum==len(binarycode):
binarysplited = binarysplited + " "
if not len(binarynospace) % 6==0:
padding = 6 - (len(binarynospace) % 6)
binarynospace = binarynospace + str("0"*padding)
padding = str(padding)
s = f'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'
n = 1
b64chars = [s[i:i+n] for i in range(0, len(s), n)]
s = f'{binarynospace}'
n = 6
converted = [s[i:i+n] for i in range(0, len(s), n)]
base64Encoded = ""
biggest = 2**(6 - 1)
for converting in converted:
number = 0
for convert in converting:
number = number + int(biggest * int(convert))
biggest = biggest / 2
base64Encoded = base64Encoded + str(b64chars[number])
biggest = 2**(6 - 1)
while not len(binarynospace) % 8==0:
binarynospace,base64Encoded = binarynospace + "000000",base64Encoded + "="
base64Encode("INCLUDED BASE64 ENCODER WITH 51 LINES!!!")
print(base64Encoded)