Constructing the strings with all possible values of consecutive difference and comparing them with staring string S .
for it in difference : NEW_LINE INDENT index = ord ( s [ 0 ] ) - ord ( ' a ' ) NEW_LINE reconstruct = " " NEW_LINE flag = 0 NEW_LINE i = 0 NEW_LINE while ( ( i < len ( s ) ) and ( flag <= 1 ) ) : NEW_LINE INDENT reconstruct += alphabets [ index ] NEW_LINE index += it NEW_LINE if ( index < 0 ) : NEW_LINE INDENT index += 26 NEW_LINE DEDENT index %= 26 NEW_LINE if ( reconstruct [ i ] != s [ i ] ) : NEW_LINE INDENT flag += 1 NEW_LINE hold_i = i NEW_LINE hold_l = s [ i ] NEW_LINE DEDENT i += 1 NEW_LINE DEDENT if ( flag == 1 ) : NEW_LINE INDENT s [ hold_i ] = reconstruct [ hold_i ] NEW_LINE break NEW_LINE DEDENT DEDENT if ( flag > 1 ) : NEW_LINE INDENT hold_i = 0 NEW_LINE hold_l = s [ 0 ] NEW_LINE temp = ( ord ( s [ 1 ] ) - ord ( ' a ' ) - ( ord ( s [ 2 ] ) - ord ( s [ 1 ] ) ) ) % 26 NEW_LINE if ( temp < 0 ) : NEW_LINE INDENT temp += 26 NEW_LINE DEDENT s [ 0 ] = alphabets [ temp ] NEW_LINE DEDENT print ( hold_i , " - > " , hold_l ) NEW_LINE print ( " " . join ( s ) ) NEW_LINE