Skip to content

Instantly share code, notes, and snippets.

@cahnory
Last active October 3, 2015 13:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cahnory/6abfacd9818cdc583da1 to your computer and use it in GitHub Desktop.
Save cahnory/6abfacd9818cdc583da1 to your computer and use it in GitHub Desktop.
Generated by SassMeister.com.
<div class="box"></div>
// ----
// 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));
}
foo {
msg: "I love you.";
key: "somewhere over the rainbow";
/**/
crypt: "5oID!we,Duk";
uncrypt: "I love you.";
bad-key: "Cdqstl!P4j2";
}
<div class="box"></div>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment