Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/micheleriva/caesar-cipher

๐Ÿ‘‘ Dead Simple Caesar Cipher written in Haskell
https://github.com/micheleriva/caesar-cipher

caesar-cipher cipher cipher-algorithms haskell haskell-learning haskell-library

Last synced: 7 days ago
JSON representation

๐Ÿ‘‘ Dead Simple Caesar Cipher written in Haskell

Awesome Lists containing this project

README

        

Caesar Cipher



s i m p l e ยท h a s k e l l ยท i m p l e m e n t a t i o n







My goal with this project was to build a Caesar Cipher with the minimum effort.

Why? Because I strongly believe that an awesome language such as Haskell, has the potential to transform the following verbose code in something beautiful:

```php
= "A") && ($c <= 'Z')) {
if((ord($c) + $offset) > ord("Z")) {
$encrypted_text .= chr(ord($c) + $offset - 26);
} else {
$encrypted_text .= chr(ord($c) + $offset);
}
} else {
$encrypted_text .= " ";
}
$i++;
}
return $encrypted_text;
}

function decrypt($str, $offset) {
$decrypted_text = "";
$offset = $offset % 26;
if($offset < 0) {
$offset += 26;
}
$i = 0;
while($i < strlen($str)) {
$c = strtoupper($str{$i});
if(($c >= "A") && ($c <= 'Z')) {
if((ord($c) - $offset) < ord("A")) {
$decrypted_text .= chr(ord($c) - $offset + 26);
} else {
$decrypted_text .= chr(ord($c) - $offset);
}
} else {
$decrypted_text .= " ";
}
$i++;
}
return $decrypted_text;
}
```

why the `hwem` (caesar 2) should I write such an horrible php code when there's Haskell?

# License
[MIT](/LICENSE.md)