From ab36234ff3e3a3d627d29d3b3be58dd99a2d1bf6 Mon Sep 17 00:00:00 2001 From: belliash Date: Tue, 17 Dec 2019 14:41:27 +0100 Subject: [PATCH] Add beaufort cipher test. --- tests/beaufort_cipher.aer | 43 +++++++++++++++++++++++++++++++++++++++ tests/beaufort_cipher.exp | 1 + 2 files changed, 44 insertions(+) create mode 100644 tests/beaufort_cipher.aer create mode 100644 tests/beaufort_cipher.exp diff --git a/tests/beaufort_cipher.aer b/tests/beaufort_cipher.aer new file mode 100644 index 0000000..318a624 --- /dev/null +++ b/tests/beaufort_cipher.aer @@ -0,0 +1,43 @@ +class Beaufort { + private string $cipher; + + public string __construct(string $text, string $key) { + string $alphabet = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'; + for(int $i = 0; $i < strlen($text); $i++) { + int $j; + char $c0 = $text[$i]; + char $c1 = $key[$i % strlen($key)]; + int $start = 0; + for($j = 0; $j < 26; $j++) { + if($alphabet[$j] == strtoupper($c0)) { + $start = $j; + break; + } + } + int $offset = 0; + for($j = $start; $j < $start + 26; $j++) { + int $letter = $j %26; + if($alphabet[$letter] == strtoupper($c1)) { + break; + } + $offset++; + } + $this->cipher += $alphabet[$offset]; + } + } + + public string getCipher() { + return $this->cipher; + } + +} + +class Program { + + public void main() { + object $beaufort = new Beaufort('thisisasecretmessage', 'youwillneverguessit'); + var_dump($beaufort->getCipher()); + } + +} + diff --git a/tests/beaufort_cipher.exp b/tests/beaufort_cipher.exp new file mode 100644 index 0000000..10af5a1 --- /dev/null +++ b/tests/beaufort_cipher.exp @@ -0,0 +1 @@ +string(20 'FHMEATLVATNNNIAAAINU')