Quick actions

cmd+k|ctrl+k

Navigation

Languages

ข้อ 3

Snippet info

Language

Php

Visibility

public

Author

64160267

Created

2023-09-28T07:43:50.970833Z

Updated

2023-09-28T07:45:58.723442Z

<?php 
//64160267 Kanokpol Promtha
// Caesar

function exam03($s,$text)
{
    $result = "";
 
    //text
    for ($i = 0; $i < strlen($text); $i++)
    {
        // transformation to each
        if (ctype_upper($text[$i]))
            $result = $result.chr((ord($text[$i]) +
                               $s - 65) % 26 + 65);
    else
        $result = $result.chr((ord($text[$i]) +
                           $s - 97) % 26 + 97);
    }
    // Return the resulting string
    return $result;
}

function test_01(){
    if(exam03(3, "ABC") == "DEF"){
        echo "pass";
    } else {
        echo "fail";
    }
    if(exam03(3, "ZXY") == "CAB"){
    echo "pass";
    } else {
    echo "fail";
    }
}

test_01();
INFO