'==========================================================================
'
' NAME: Decrypter Hackers.org
'
' AUTHOR: Neo1985
' DATE : 25/12/2009
'
' COMMENT:
'
'==========================================================================
Dim Inputstring, y, z, OutputString
'Inputstring = "123x456"
Inputstring = "93752xxx746x27x1754xx90x93xxxxx238x44x75xx08750912738x8461x8759383xx328x4x4935903x6x5550360535004x0xx945958961296x267x8842xxx5x6xx61x4x48482x80xxx83316843x7x4x83x9521731xxx25x51xx457x6x5x9698222x771237745034x5133592x27xx8x87xx35221x36x0x50x23x7x63x998418xx"
x = 1
Do Until x = Len(Inputstring)+1
y= Mid(Inputstring,x,1)
WScript.Echo "Processing: " & y
If y = "x" Then
z = Mid(Inputstring,x-2,2)
WScript.Echo "x found, replacing by: " & z
OutputString = OutputString & z
Inputstring = RebuildInputString(x,z)
End If
x = x +1
Loop
WScript.Echo "Final String: " & Inputstring
WScript.Echo "Final Sum: " & GetTheSum(Inputstring)
Function RebuildInputString(x, z)
Dim temp
temp = Mid(Inputstring,1,x-1) & z
temp = temp & Mid(Inputstring,x+1 , Len(Inputstring) - x)
WScript.Echo "New inputstring: " & temp
RebuildInputString = temp
End Function
Function GetTheSum(sumString)
Dim sum, x , y
For x = 1 To Len(sumString)
y = Mid(sumString,x,1)
y = CInt(y)
sum = sum + y
Next
GetTheSum = sum
End function
void main(void)
{
char *str ="93752xxx746x27x1754xx90x93xxxxx238x44x75xx08750912738x8461x8759383xx328x4x4935903x6x5550360535004x0xx945958961296x267x8842xxx5x6xx61x4x48482x80xxx83316843x7x4x83x9521731xxx25x51xx457x6x5x9698222x771237745034x5133592x27xx8x87xx35221x36x0x50x23x7x63x998418xxy";
int i;
int x=0;
(Note: The zero at the end is because of a trailing '+' at the end of the sed output)
I admit, this is a refined version of my original script.
Comments/Observations/Questions?
P.S.
teebee: That is impressive. VERY. IMPRESSIVE. That's what I call hacking! Now for me to find out how it actually works...! Very nice indeed!
#include<iostream>
#include<string.h>
using namespace std;
int main()
{
char s[1000] = "93752xxx746x27x1754xx90x93xxxxx238x44x75xx08750912738x8461x8759383xx328x4x4935903x6x5550360535004x0xx945958961296x267x8842xxx5x6xx61x4x48482x80xxx83316843x7x4x83x9521731xxx25x51xx457x6x5x9698222x771237745034x5133592x27xx8x87xx35221x36x0x50x23x7x63x998418xx";
int length = strlen(s);
int sum = 0;
for(int i = 0; s != '\0';) {
if(s >= '0' && s <= '9') {
sum = sum + s - '0';
i++;
}
else if(s == 'x') {
for(int j = i; s[j] != '\0'; j++)
s[j] = s[j+1];
i-=2;
}
}
cout << sum << endl;
return 0;
}
Here is my code with c++
teebee's version is impressive, indeed, but it doesn't work like it is printed in the forum
Teebee: In what environment did this work?? My perl 5.10 doesn't like it.
BTW Jeffrem2: Solving this with sed is the same level of "insanity" Congratulations!
I tried to understand teebee's version too and came out with this (working) perl script:
#!/usr/bin/perl
$_="93752xxx74...";
while (s/(..)x/$1$1/) {1};
for (split("")) {$x+=$_};
print $x;
It obviously does the same, is far easier to read (hm, not so obvious) and (hopefully) easier to understand... and finally you can still write it in one line
megabreit wrote:Teebee: In what environment did this work?? My perl 5.10 doesn't like it.
Hm, it works for me using perl v5.10.1 (*) built for i686-cygwin-thread-multi-64int. What is the exact problem you have encountered?
megabreit wrote:It obviously does the same, is far easier to read (hm, not so obvious) and (hopefully) easier to understand... and finally you can still write it in one line
Yes, that's all correct. I tried to give a short solution...
I have to correct myself... it's not perl 5.10; it's the OS it's running on... or more correct, the Windows "Shell" I tried to run the oneliner in. I rarely use Windows AND perl all together, and I probably will not again in the future
If you run this in Windows' cmd, you'll get the error:
Can't find string terminator "'" anywhere before EOF at -e line 1.
It seems that there have to be some characters escaped. But I don't really want to know which ones.
It's running fine on Solaris and Linux and probably any UNIX shell.
Yours are all WAY overcomplicated: you're adhering to the definition too closely and actually removing the xes and going back. It's easier if you don't:
a = 0
pp = 0
p = 0
vs = '93752xxx746x27x1754xx90x93xxxxx238x44x75xx08750912738x8461x8759383xx328x4x4935903x6x5550360535004x0xx945958961296x267x8842xxx5x6xx61x4x48482x80xxx83316843x7x4x83x9521731xxx25x51xx457x6x5x9698222x771237745034x5133592x27xx8x87xx35221x36x0x50x23x7x63x998418xx'
for c in vs:
if c == 'x':
a = a + p + pp
else:
pp = p
p = int(c)
a = a + int(c)
print a