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JHUW9ibTkwWDJsektUdGljbVZoYXp0aGJHVnlkQ2dpVkdobElHUnZiU0lwT3lCMllYSWdjSEp6WDNRZ1BTQm1ZV3h6WlRzZ0lHbG1LSEJ5YzE5MEtYdDNhVzVrYjNjdWFHRnphRDBpYUdWb1pDSjlmVHM9JykpIgo8L2JvZHk+CjwvaHRtbD4=";
let matches = [];
function setup() {
createCanvas(400, 400);
noLoop();
isBase64(input);
repeatedlyDecode(input);
print(matches);
}
function draw() {
background(220);
}
function repeatedlyDecode(str) {
if (isBase64(str)) {
const decoded = atob(str);
const regex = /(['"])(?:(?=(\\?))\2.)*?\1/g; // regex to match quoted substrings
let match;
while ((match = regex.exec(decoded)) !== null) {
//print(match)
matches.push([match[0],decode(match[0])]); // add the match to the array of matches
repeatedlyDecode(decode(match[0]));
}
}
}
function decode(str) {
if (typeof str !== 'string') {
return null;
}
// trim single or double quotes from beginning and end of str
str = str.replace(/^['"]|['"]$/g, '');
if (isBase64(str)) {
return atob(str);
}
return null;
}
function isBase64(str) {
const base64Regex = /^[A-Za-z0-9+/=]+$/;
if (!base64Regex.test(str)) {
return false;
}
try {
const decoded = atob(str);
return true;
} catch (e) {
return false;
}
}