Skip to content

Instantly share code, notes, and snippets.

@lbvf50mobile
Last active October 28, 2020 15:01
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 lbvf50mobile/92f252842701e4116b7447ba66855ba4 to your computer and use it in GitHub Desktop.
Save lbvf50mobile/92f252842701e4116b7447ba66855ba4 to your computer and use it in GitHub Desktop.
Just PHP FUN 139.
<?php
# https://www.codewars.com/kata/559536379512a64472000053 Playing with passphrases.
function playPass($s, $n) {
$s = str_split($s);
$s = array_map(function($x) use ($n){
if(preg_match('/[A-Z]/',$x)){
return char($x,$n);
}
if(preg_match('/[0-9]/',$x)){
return digit($x);
}
return $x;
},$s);
for($i = 0; $i < count($s); $i += 1) if(1 == $i%2) $s[$i] = strtolower($s[$i]);
return strrev(implode($s));
}
function char($c,$n){
return chr( ((ord($c) + $n - ord("A"))%(ord("Z")-ord("A")+1)) + ord("A"));
}
function digit($c){
$ans = strval(9 - intval($c));
return $ans;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment