Is there a way to map/translate a pattern-lock to a numeric PIN? I just encrypted my Moto X (Gen 1) (KitKat 4.4.4) using the default encryption option from the Settings > Security menu. After the encryption process finished, it asks me, "Type password to decrypt storage". Only there's one problem: it never asked me for a password.

It seems I'm not the only one who experienced this. I've tried my Google password like 3 times, and, like that other poor soul, I haven't been able to find a way to map my pattern-lock to a PIN, which might be what Android used for the encryption.

For the mappings, I have tried a standard phone dial pad:

1 2 3
4 5 6
7 8 9


and a standard keyboard numpad:

7 8 9
4 5 6
1 2 3


and a wild guess based on how a developer might do it:

0 1 2
3 4 5
6 7 8


Presumably, though not necessarily, Android stores that pattern as a string or number somehow. Given a certain unlock pattern, how do I find the string or number that represents that pattern?



To the moderators: I'm fine deleting this question if it's not on-topic. I think the question would have been on-topic if the answer fixed my problem. I'm not sure how you guys see that.
I downloaded the Android source and found the answer. The wild guess turns out to be right. This is the mapping:

0 1 2
3 4 5
6 7 8


If your pattern is from top-left to top-right (0->1->2) then down to bottom-right (2->5->8), the string version of the password is "01258".

The source for this comes from LockPatternUtils in package com.android.internal.widget:

/**
 * Serialize a pattern.
 * @param pattern The pattern.
 * @return The pattern in string form.
 */
public static String patternToString(List&lt;LockPatternView.Cell&gt; pattern) {
    if (pattern == null) {
        return "";
    }
    final int patternSize = pattern.size();

    byte[] res = new byte[patternSize];
    for (int i = 0; i &lt; patternSize; i++) {
        LockPatternView.Cell cell = pattern.get(i);
        res[i] = (byte) (cell.getRow() * 3 + cell.getColumn());
    }
    return new String(res);
}


where the rows and columns are both {0,1,2}.

However, as I said in my question, I tried this mapping with my pattern, and it doesn't work to unlock my encryption. This turned out to be a dead end, but I hope this answer is helpful to others with a similar problem. (Note again that the other person who had this problem also tried to find the pattern-lock to PIN mapping, but the answer wasn't out there.)