Code: sub process_tripcode($;$$$$) { my ($name,$tripkey,$secret,$charset,$nonamedecoding)=@_; $tripkey="!" unless($tripkey); if($name=~/^(.*?)((?<!&)#|\Q$tripkey\E)(.*)$/) { my ($namepart,$marker,$trippart)=($1,$2,$3); my $trip; $namepart=decode_string($namepart,$charset) unless $nonamedecoding; $namepart=clean_string($namepart); if($secret and $trippart=~s/(?:\Q$marker\E)(?<!&#)(?:\Q$marker\E)*(.*)$//) # do we want secure trips, and is there one? { my $str=$1; my $maxlen=255-length($secret); $str=substr $str,0,$maxlen if(length($str)>$maxlen); #$trip=$tripkey.$tripkey.encode_base64(rc4(null_string(6),"t".$str.$secret)," "); $trip=$tripkey.$tripkey.hide_data($1,6,"trip",$secret,1); return ($namepart,$trip) unless($trippart); # return directly if there's no normal tripcode } # trips are processed as Shift_JIS whenever possible eval 'use Encode qw(decode encode)'; unless($@) { $trippart=decode_string($trippart,$charset); $trippart=encode("Shift_JIS",$trippart,0x0200); } $trippart=clean_string($trippart); my $salt=substr $trippart."H..",1,2; $salt=~s/[^\.-z]/./g; $salt=~tr/:;<=>?@[\\]^_`/ABCDEFGabcdef/; $trip=$tripkey.(substr crypt($trippart,$salt),-10).$trip; return ($namepart,$trip); } return clean_string($name) if $nonamedecoding; return (clean_string(decode_string($name,$charset)),""); } sub decode_string($;$$) { my ($str,$charset,$noentities)=@_; my $use_unicode=$has_encode && $charset; $str=decode($charset,$str) if $use_unicode; $str=~s{(&#([0-9]*)([;&])|&#([x&])([0-9a-f]*)([;&]))}{ my $ord=($2 or hex $5); if($3 eq '&' or $4 eq '&' or $5 eq '&') { $1 } # nested entities, leave as-is. elsif(forbidden_unicode($2,$5)) { "" } # strip forbidden unicode chars elsif($ord==35 or $ord==38) { $1 } # don't convert & or # elsif($use_unicode) { chr $ord } # if we have unicode support, convert all entities elsif($ord<128) { chr $ord } # otherwise just convert ASCII-range entities else { $1 } # and leave the rest as-is. }gei unless $noentities; $str=~s/[\x00-\x08\x0b\x0c\x0e-\x1f]//g; # remove control chars return $str; } sub clean_string($;$) { my ($str,$cleanentities)=@_; if($cleanentities) { $str=~s/&/&/g } # clean up & else { $str=~s/&(#([0-9]+);|#x([0-9a-fA-F]+);|)/ if($1 eq "") { '&' } # change simple ampersands elsif(forbidden_unicode($2,$3)) { "" } # strip forbidden unicode chars else { "&$1" } # and leave the rest as-is. /ge # clean up &, excluding numerical entities } $str=~s/\</</g; # clean up brackets for HTML tags $str=~s/\>/>/g; $str=~s/"/"/g; # clean up quotes for HTML attributes $str=~s/'/'/g; $str=~s/,/,/g; # clean up commas for some reason I forgot $str=~s/[\x00-\x08\x0b\x0c\x0e-\x1f]//g; # remove control chars return $str; }
Обрабатывается трипкод Что в точности происходит сказать нельзя, потому что неизвестны функции decode_string, clean_string...