Let us consider a cipher that works like the following:

  • Plaintext is encoded to Base64.
  • The characters in the encoded plaintext are substituted with a randomly shuffled character set (a-z, 0-9, A-Z, /, +).

The shuffled alphabet are the key. How do I decipher it to get the base64 encoded string without knowing the shuffled character set?

  • 1
    $\begingroup$ i guess you could break it into 6-bit groups and perform a frequency analysis, even better if you can see a known large plaintext, then you can crack it completely $\endgroup$ Commented Jan 20, 2017 at 0:29
  • $\begingroup$ Related Q/A here. Note that due to the shift you can be reasonably certain that the highest bit is set to zero for ASCII characters. Fun thing is that this will affect multiple positions in the encoding, which should make it easier to perform frequency analysis. I think an answer should definitely contain tricks that uses this information. Also, only certain characters are possible at the end of base 64 ciphertext (where the input in octets is not dividable by 3), further restricting the possible values. $\endgroup$
    – Maarten Bodewes
    Commented Jan 20, 2017 at 9:35
  • $\begingroup$ The key size is about ~88 bits (I think the key size is $26!$) so brute forcing is definitely out by the way. $\endgroup$
    – Maarten Bodewes
    Commented Jan 20, 2017 at 9:41
  • $\begingroup$ This question is missing which information can be assumed to be present to distinguish the result of decoding. As base64 can encode any binary you cannot decode without information about the plaintext. It would only possibly leak a tiny bit of information at the end of the base64 encoding (as the last character only encodes 2, 4 or 6 bits out of 8). $\endgroup$
    – Maarten Bodewes
    Commented Feb 2, 2017 at 13:28
  • $\begingroup$ Have you looked at this link? crypto.stackexchange.com/questions/20802/… $\endgroup$
    – Carl Knox
    Commented Feb 7, 2017 at 14:35

1 Answer 1


Base64 encoding regroups three consecutive 8-bit values (0-255) into four 6-bit values (0-63). Each value is used to index of a small ASCII array which is typically sequential, such as,

var base64Map = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=';

Base64 decoding is the reverse process. Each character's position is an indexof a matching ASCII array which results in a 6-bit value. Four of these are regrouped into three 8-bit values.

In your case, I suspect the base64Map was shuffled, rather than a separate shuffle operation of the encoded plaintext. If this is the case, then you need to match the order of the encoding array. If truly random, this would become a monumental effort. Perhaps try a Caesar Shift of the array.


Not the answer you're looking for? Browse other questions tagged or ask your own question.