Skip to content

Instantly share code, notes, and snippets.

@tetsunosuke
Created October 7, 2019 08:27
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 tetsunosuke/7c5cc93f5c1032edffddf78db58b9ab7 to your computer and use it in GitHub Desktop.
Save tetsunosuke/7c5cc93f5c1032edffddf78db58b9ab7 to your computer and use it in GitHub Desktop.
シーザー暗号
<?php
// 入力として与えられた暗号文
$input = "AXBCDYE";
$inputLength = strlen($input);
$alphabets = "ABCDEFGHIJKLMNOPQRSTUWXYZ";
$alphabetsLength = strlen($alphabets);
$output = "";
for ($i = 0; $i < $inputLength; $i++) {
for($j=0; $j < $alphabetsLength; $j++) {
if ($input[$i] === $alphabets[$j]) {
$tmp = $j - 2;
$output .= $alphabets[$tmp];
}
}
}
echo $output . PHP_EOL;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment