Function Rot_num([string]$str, $n)
{
$value=""
For ($index= 0;$index -lt $str.length;$index++){
$ch= [byte][char]($str.substring($index,1))
if ($ch-ge 97 -and $ch -le 109){$ch=$ch+ $n}
else {
if ($ch-ge 110 -and $ch -le 122){$ch=$ch- $n}
else {
if ($ch-ge 65 -and $ch -le 77){$ch=$ch+ $n}
else {
if ($ch-gt 78 -and $ch -le 90){$ch=$ch -$n}
}
}
}
$value=$value+ [char]$ch
}
Return $value
}
After you have pasted the function above, you can start using it to see
how it works. Just type rot_num followed by a string and the number
13. Then you can do the same to decrypt the value by typing rot_num
encrypted message and the number 13 again. It should decrypt the
encrypted message.
PS C:\> Rot_num Hell0Urhere2014 13
Uryy0Heurer2014
PS C:\> Rot_num Uryy0Heurer2014 13
Hell0Urhere2014
So, talk about what this code does and what is ROT-13.
PS C:\> Rot_num Hell0Urhere2014 13
Uryy0Heurer2014
PS C:\> Rot_num Uryy0Heurer2014 13
Hell0Urhere2014
So, talk about what this code does and what is ROT-13.
Thank you for the code you posted. In the code, you need to change:
ReplyDeleteif ($ch-gt 78 -and $ch -le 90){$ch=$ch -$n}
to
if ($ch-ge 78 -and $ch -le 90){$ch=$ch -$n}
Failure to do so does not decode the capital letter N