Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Number.prototype.mod = function(n) {
- return ((this%n)+n)%n;
- }
- function rotplus(str, startIdx, addEachRot) {
- var result = '';
- for (var i = 0; i < str.length; ++i) {
- var rot = (startIdx + i * addEachRot);
- var c = str.charCodeAt(i) - 33 + rot;
- result += String.fromCharCode(33 + (c.mod(90)));
- }
- return result;
- }
- function encode(str, b64Count, rotStart, addEachRot) {
- result = str;
- for (var i = 0; i < b64Count; ++i) {
- result = btoa(result);
- }
- return rotplus(result, rotStart, addEachRot);
- }
- function decode(str, b64Count, rotStart, addEachRot) {
- result = rotplus(str, -rotStart, -addEachRot); // to undo rotplus, just pass parameters as negative
- for (var i = 0; i < b64Count; ++i) {
- result = atob(result);
- }
- return result;
- }
- // The following code is a way you can brute-force any parameters.
- // The use of base64 as the final decoding step means _most_ parameters are
- // obviously invalid as they don't result in a valid base64 string.
- // additionally, due to the use of modulus there is a set amount of values
- // that can be used for rotStart and addEachRot so brute-forcing is a
- // pretty reasonable thing to do
- for (var b64Count = 0; b64Count < 30; ++b64Count) {
- for (var rs = 0; rs < 90; ++rs) {
- for (var aer = 0; aer < 90; ++aer) {
- try {
- console.log(decode(str, b64Count, rs, aer) + " (used params " + b64Count + "," + rs + "," + aer + ")"); // replace str with whatever you're trying to decode
- }
- catch (e) {
- // if an error is thrown (from atob(), which is the base64 decoder) then
- // we know this solution is not valid.
- }
- }
- }
- }
- // after running the above, you should get a bunch of text in your console. It should
- // be fairly obvious which bit of text is the correct answer
Advertisement
Add Comment
Please, Sign In to add comment