Last active
April 9, 2018 16:52
-
-
Save pascalduez/a5d718b311c452bd4f00 to your computer and use it in GitHub Desktop.
ROT13 implementation in Sass.
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
// ---- | |
// Sass (v3.3.8) | |
// Compass (v1.0.0.alpha.18) | |
// ---- | |
// ROT13 implementation in Sass. | |
// https://en.wikipedia.org/wiki/ROT13 | |
@function rot13($str) { | |
$chars: 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'; | |
$result: ''; | |
@for $i from 1 through str-length($str) { | |
$char: str-slice($str, $i, $i); | |
$index: str-index($chars, $char); | |
$pos: 0; | |
@if $index { | |
// $index > 26 == Lower case | |
// $index <= 26 == Upper case | |
$start: if($index > 26, 27, 1); | |
$pos: (($index - $start) + 13) % 26 + $start; | |
} | |
$result: $result + if($index, str-slice($chars, $pos, $pos), $char); | |
} | |
@return $result; | |
} | |
Test { | |
$decoded: 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'; | |
$encoded: 'NOPQRSTUVWXYZABCDEFGHIJKLMnopqrstuvwxyzabcdefghijklm'; | |
encode: rot13($decoded) == $encoded; | |
decode: rot13($encoded) == $decoded; | |
chars: rot13('ifzTf45:;Kù^é(àçerijAhZg') | |
} |
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
@charset "UTF-8"; | |
Test { | |
encode: true; | |
decode: true; | |
chars: "vsmGs45:;Xù^é(àçrevwNuMt"; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment