Last active
August 29, 2015 14:25
-
-
Save fxlae/2b8b6387f9a00316c87f to your computer and use it in GitHub Desktop.
A sample implementation for mapping 10 digit TOTP tokens to 5 digit tokens that are accepted by Steam.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
object SteamTOTPConverter { | |
private val base26Chars = "0123456789ABCDEFGHIJKLMNOP" | |
private val steamChars = "23456789BCDFGHJKMNPQRTVWXY" | |
private val charMap = (base26Chars zip steamChars) toMap | |
private def toBase26(number: Int) = Integer.toString(number, 26).toUpperCase | |
def convertFrom(totpToken: Int) = { | |
toBase26(totpToken) | |
.takeRight(5) | |
.map(char => charMap.getOrElse(char, '?')) | |
.padTo(5, '2') | |
.reverse | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment