Skip to content

Instantly share code, notes, and snippets.

@fxlae
Last active August 29, 2015 14:25
Show Gist options
  • Save fxlae/2b8b6387f9a00316c87f to your computer and use it in GitHub Desktop.
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.
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