How can I guess the encoding of a string in Perl?

前端 未结 3 1129
天命终不由人
天命终不由人 2020-11-30 03:46

I have a Unicode string and don\'t know what its encoding is. When this string is read by a Perl program, is there a default encoding that Perl will use? If so, how can I fi

3条回答
  •  野趣味
    野趣味 (楼主)
    2020-11-30 04:43

    You can use the following code also, to encrypt and decrypt the code

    sub ENCRYPT_DECRYPT() {
        my $Str_Message=$_[0];
        my  $Len_Str_Message=length($Str_Message);
    
        my  $Str_Encrypted_Message="";
        for (my $Position = 0;$Position<$Len_Str_Message;$Position++){
            my  $Key_To_Use = (($Len_Str_Message+$Position)+1);
                $Key_To_Use =(255+$Key_To_Use) % 255;
            my  $Byte_To_Be_Encrypted = substr($Str_Message, $Position, 1);
            my  $Ascii_Num_Byte_To_Encrypt = ord($Byte_To_Be_Encrypted);
            my  $Xored_Byte = $Ascii_Num_Byte_To_Encrypt ^ $Key_To_Use;
                my  $Encrypted_Byte = chr($Xored_Byte);
            $Str_Encrypted_Message .= $Encrypted_Byte;
    
        }
        return $Str_Encrypted_Message;
    }
    
     my $var=&ENCRYPT_DECRYPT("hai");
     print &ENCRYPT_DECRYPT($var);
    

提交回复
热议问题