Last active
December 24, 2019 15:22
-
-
Save shouth/6cebf2a53140637e56856df2806086d6 to your computer and use it in GitHub Desktop.
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 Base64 { | |
def main(args: Array[String]): Unit = { | |
val str = "input here" | |
val result = str.getBytes | |
.flatMap(b => (0 until 8).map(n => (b >> (7 - n)) & 1)) | |
.grouped(6) | |
.map(b => b.indices.map(n => b(n) << (5 - n)).sum) | |
.map("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"(_)) | |
.grouped(4) | |
.flatMap(_.padTo(4, '=')) | |
.mkString | |
println(result) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment