Exemplo n.º 1
0
function shift($char, $key)
{
    // Convert upper to lower.
    if (ord($char) >= 65 && ord($char) <= 90) {
        $temp = strtolower($char);
        $char = $temp;
    }
    $code = letterToNum($char);
    $shifted = $code + $key;
    // If it isn't a letter.
    if (ord($char) >= 97 && ord($char) <= 122) {
        if ($key < 0) {
            if ($shifted < 0) {
                $coded = 26 + $shifted;
                $newCh = NumToLetter($coded);
            } else {
                $coded = $shifted;
                $newCh = NumToLetter($coded);
            }
            return $newCh;
        } else {
            if ($shifted > 25) {
                $coded = $shifted % 26;
                $newCh = NumToLetter($coded);
            } else {
                $coded = $shifted;
                $newCh = NumToLetter($coded);
            }
        }
        return $newCh;
    } else {
        return $char;
    }
}
Exemplo n.º 2
0
function clean($plaintext)
{
    $strippedText = "";
    $cleanText = "";
    for ($i = 0; $i < strlen($plaintext); $i++) {
        if (ord($plaintext[$i]) >= 65 && ord($plaintext[$i]) <= 90) {
            $strippedText .= strtolower($plaintext[$i]);
        } else {
            if (ord($plaintext[$i]) >= 97 && ord($plaintext[$i]) <= 122) {
                $strippedText .= $plaintext[$i];
            }
        }
    }
    $cleanText .= letterToNum($strippedText[0]);
    for ($j = 1; $j < strlen($strippedText); $j++) {
        $cleanText .= "," . letterToNum($strippedText[$j]);
    }
    return $cleanText;
}