I think this would work (but I haven't tested it):
Convert the string to an array of integers called FORWARD.
Copy and flip the array into REVERSE. Subtract the values of REVERSE, offset by (0..length), pairwise from FORWARD. Then, just keep track of the longest block of zeros (index in FORWARD and length)
corpus: ilikeracecarstoo
FORWARD: (8,11,8,10,4,17,0,2,4,2,0,17,19,14,14)
REVERSE: (14,14,19,17,0,2,4,2,0,17,4,10,8,11,8)
In this case, the password appears at an offset of 2
REVERSE(2): (0,0,14,14,19,17,0,2,4,2,0,17,4,10,8)
SUBTRACTED: (-8,-11,6,4,15,0,0,0,0,0,0,0,-15,-4,-6)
The longest zero block occurs at FORWARD[5] and ends at FORWARD[11]... in other words, racecar.
Should be quicker than brute force.
Convert the string to an array of integers called FORWARD. Copy and flip the array into REVERSE. Subtract the values of REVERSE, offset by (0..length), pairwise from FORWARD. Then, just keep track of the longest block of zeros (index in FORWARD and length)
corpus: ilikeracecarstoo FORWARD: (8,11,8,10,4,17,0,2,4,2,0,17,19,14,14) REVERSE: (14,14,19,17,0,2,4,2,0,17,4,10,8,11,8)
In this case, the password appears at an offset of 2 REVERSE(2): (0,0,14,14,19,17,0,2,4,2,0,17,4,10,8) SUBTRACTED: (-8,-11,6,4,15,0,0,0,0,0,0,0,-15,-4,-6)
The longest zero block occurs at FORWARD[5] and ends at FORWARD[11]... in other words, racecar.
Should be quicker than brute force.