Created
January 19, 2015 10:34
-
-
Save oprypin/4c84e0ee0064e17d5f52 to your computer and use it in GitHub Desktop.
urlsafe base64
This file contains hidden or 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
import strutils | |
from base64 import nil | |
proc encodeUrlSafe(s: string): string = | |
result = base64.encode(s, newLine="") | |
while result.endsWith("="): | |
result = result.substr(0, result.high-1) | |
result = result.replace('+', '-').replace('/', '_') | |
proc decodeUrlSafe(s: string): string = | |
var s = s | |
while s.len mod 4 > 0: | |
s &= "=" | |
base64.decode(s).replace('+', '-').replace('/', '_') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment