Last active
October 3, 2015 13:58
-
-
Save cahnory/6abfacd9818cdc583da1 to your computer and use it in GitHub Desktop.
Generated by SassMeister.com.
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
<div class="box"></div> |
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
// ---- | |
// libsass (v3.2.5) | |
// ---- | |
$chars: '0123456789' | |
+ 'abcdefghijklmnopqrstuvwxyz' | |
+ 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' | |
+ ',.!-_ ';//poc ;) | |
$chars-length: str-length($chars); | |
@function crypt($string, $key) { | |
$string: crypt-split($string); | |
$key: crypt-split($key); | |
$res: (); | |
$cursor: 1; | |
@each $number in $string { | |
$res: append($res, ($number + nth($key, $cursor))%$chars-length); | |
$cursor: if($cursor == length($key), 1, $cursor + 1); | |
} | |
@return crypt-join($res); | |
} | |
@function uncrypt($string, $key) { | |
$numbers: crypt-split($string); | |
$key: crypt-split($key); | |
$res: (); | |
$cursor: 1; | |
@each $number in $numbers { | |
$sum: $number - nth($key, $cursor); | |
@if $sum < 1 { | |
$sum: $chars-length + $sum%$chars-length; | |
} | |
$res: append($res, $sum); | |
$cursor: if($cursor == length($key), 1, $cursor + 1); | |
} | |
@return crypt-join($res); | |
} | |
@function crypt-split($string) { | |
$res: (); | |
@for $i from 1 through str-length($string) { | |
$res: append($res, str-index($chars, str-slice($string, $i, $i))); | |
} | |
@return $res; | |
} | |
@function crypt-join($numbers) { | |
$res: (); | |
@each $number in $numbers { | |
$res: $res + str-slice($chars, $number, $number); | |
} | |
@return $res; | |
} | |
$msg: 'I love you.'; | |
$key: 'somewhere over the rainbow'; | |
$bad: 'yaha'; | |
foo { | |
msg: $msg; | |
key: $key; | |
/**/ | |
crypt: crypt($msg, $key); | |
uncrypt: uncrypt(crypt($msg, $key), $key); | |
bad-key: uncrypt(crypt($msg, $key), $bad); | |
///**/ | |
//split: crypt-split($msg); | |
//join: crypt-join(crypt-split($msg)); | |
} |
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
foo { | |
msg: "I love you."; | |
key: "somewhere over the rainbow"; | |
/**/ | |
crypt: "5oID!we,Duk"; | |
uncrypt: "I love you."; | |
bad-key: "Cdqstl!P4j2"; | |
} |
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
<div class="box"></div> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment