A preserved archive of the Logical Gamers community forums, 2009-2025. The original threads and posts, served read-only. Registration, posting and private messages are gone for good.

Halloween Contest - Caeser Cipher

2.5k views · started by Kingz V ·
#1
Halloween Contest - Caeser Cipher ***VOTE NOW***
As per Zubat's request (you better submit son).

Here is my formal contest, Submissions due by Nov 1st, voting will be publicly held the following three days.

This is something I've done in an entry level course to programming, so I believe everyone here should be able to participate.

50 B.C Julius Caeser used a simple substitution cipher to secure military and government communications. To form and encrypted text, Caeser shifted the letter of the alphabet three places. In addition to this mono-alphabetic substitution cipher, Caeser strengthened his encryption by substituting Greek letters for Latin letters.

This contest will be language-agnostic. So feel free to use javascript or auto-gayy4.

Post entries to PasteBin please, if you'd like to keep you entry anonymous send a pm. :)

Good Luck, and Have Fun!

=======

Entries

=======
1. gayChief
2. stapled
3. arti
#2
I don't get it. Is the contest to shit all the characters by 3 places? Or make both an encryption and decryption algorithm based on shifting letters?
#3
A complete entry would need both encrypt/decrypt functions to verify that it works.

It's rather simple. a more complex contest would be an xor-key system, but that seemed a little complicated for a little friendly contest.
#4
So an encrpyt decrypt that shifts characters by 3?
#5
Shift characters by 2014.

var HalloCrypt = function(str) {
var chars = "HALOWENBCDFGIJKMPQRSTUVXYZ0123456789halowenbcdfgijkmpqrstuvxyz",
encryption = "",
loc, x;
for (x = 0; x < str.length; x++) {
loc = chars.indexOf(str[x]);

// If the character is in our string of characters, edit it.
if (loc != -1) {
loc += 2014;
loc = loc % chars.length;
encryption += chars[loc];
}

// Not an alphanumeric character, keep it the same.
else
encryption += str[x];
}
return encryption;
};

var DeHalloCrypt = function(str) {
var chars = "HALOWENBCDFGIJKMPQRSTUVXYZ0123456789halowenbcdfgijkmpqrstuvxyz",
encryption = "",
loc, x;
for (x = 0; x < str.length; x++) {
loc = chars.indexOf(str[x]);

// If the character is in our string of characters, edit it.
if (loc != -1) {
loc -= 2014;
while (loc < 0)
loc += chars.length;
encryption += chars[loc];
}

// Not an alphanumeric character, keep it the same.
else
encryption += str[x];
}
return encryption;
};

var a = HalloCrypt("This is a test of the emergency Logical Gamers system.");
alert(a + "\n" + DeHalloCrypt(a));[/x][/loc][/x][/x][/loc][/x]
#6
My entry? Done in C#.


private string strEnc(string text)
{
string encrypt = "";
byte[] bytes = System.Text.Encoding.UTF8.GetBytes(text);

for (int c = 0; c <= bytes.Length-1; c++)
{
encrypt += Convert.ToChar(bytes[c] - 5);
}

return encrypt;
}
private string strDec(string text)
{
string decrypt = "";
byte[] bytes = System.Text.Encoding.UTF8.GetBytes(text);

for (int c = 0; c <= bytes.Length - 1; c++)
{
decrypt += Convert.ToChar(bytes[c] + 5);
}

return decrypt;
}
[/c][/c]
#8
PHP. Left non-english characters alone so as not to screw with spaces, special chars, etc. Wasn't sure what to do with letters like z, so I just wrapped around (so z would become c).

namespace logicalgamers\contests;

class CaesarCypher
{
const LETTERS_IN_ALPHABET = 26;
const ENCRYPT = 1;
const DECRYPT = 0;

private $offset;
private $string;
private $flag;

public function __construct($string, $offset, $flag) {
$this->offset = $offset;
$this->string = $string;
$this->flag = $flag;

$this->execute();
}

private function execute() {
$this->string = implode('', array_map(function($c) {
if (! preg_match('/[a-zA-Z]/', $c)) {
return $c;
}

$char = chr(ord($c) + ($this->flag == self::ENCRYPT ?
$this->offset : 0 - $this->offset));

return preg_match('/[a-zA-Z]/', $char) ?
$char :
chr(ord($char) + ($this->flag == self::ENCRYPT ?
0 - self::LETTERS_IN_ALPHABET : self::LETTERS_IN_ALPHABET))
;
}, str_split($this->string)));
}

public function __toString() {
return $this->string;
}
}


Tests:
var_dump((string) (new CaesarCypher('ABC wxyz', 3, CaesarCypher::ENCRYPT)) === 'DEF zabc');
var_dump((string) (new CaesarCypher('DEF zabc', 3, CaesarCypher::DECRYPT)) === 'ABC wxyz');


bool(true)
bool(true)


><>
#9
Voting is now open, I set it open for 7 days.

May the most popular whore win.
#10
I am now finding out about this contest x_x
#11
Would have been a 3 way tie if I voted for myself. But I just didn't want Arti to win. :3
#12
i should've included myself. x.x

there's still some time for votes.
#13
Kingz V wrote:
i should've included myself. x.x

excuse me where is your program huh
#15
added u
#16
Voting on by plebeians. None of the other entries even work.

    static void Main()
{
Console.WriteLine(strEnc("ABC wxyz"));
Console.ReadLine();
}


Executing the program....
$mono demo.exe
<=>rstu


COOL CEASERCYPHER STAPLED.
#17
Artificial wrote:
Voting on by plebeians. None of the other entries even work.

    static void Main()
{
Console.WriteLine(strEnc("ABC wxyz"));
Console.ReadLine();
}


Executing the program....
$mono demo.exe
<=>rstu


COOL CEASERCYPHER STAPLED.


rekt
#18
Ignoring the fact that nobody (including myself since I omitted the greek/latin substitution) addresses the actual problem, everyone just shifts the character by 3 according to their ASCII value. gameCHIEFs goes one step further by checking the alphanumeric value prior to the encryption/decryption (which is silly, as z will be encrypted to a special char and then it will be unable to be decrypted), all of which can be rewritten as something as small as:

function crypt($str, $offset) { return implode('', array_map(function($c) { return preg_match('/[a-z]/i', $c) ? chr(ord($c) + $offset) : $c; }, str_split($str))) }
function encrypt($str) { return crypt($str, 3); }
function decrypt($str) { return crypt($str, -3); }


Anything which produces special chars should be an automatic fail.
You all suck at programming. Get gud.
#19
Artficial wins. It's unanimous. Screw da poll. The man is just sitting here in this thread stylin' on yall.

Side note: I would've participated in this challenge if it didn't seem so darn uninteresting. I doubt my solution would've been as comprehensive as Art's, though.
#20
Artificial wrote:
which is silly, as z will be encrypted to a special char and then it will be unable to be decrypted

No it doesn't. It starts back over at the beginning of the string. loc = loc % chars.length;

#alltalk #nocomprehension
#21
Well this was fun, let's do it again next year. :)
#22
If winner gets a badge or something

someone should come up with a clever name.
#23
Halloweenie leaf
#24
I had some awards picked out, but got lazy.
#25
GAMEchief wrote:
No it doesn't. It starts back over at the beginning of the string. loc = loc % chars.length;

#alltalk #nocomprehension


#comebackcity #chiefstrikesback