-3

hello guys i just want help to understand that algorithm i understand bitwise xor and % operators but i cant understand whats happening exactly i dont want the flag i want to underatand what to do to get the flag & thanks

PASS = input('Enter the Flag: ')
KEY = 'I know, you love decrypting Byte Code !'
I = 5
SOLUCE = [57, 73, 79, 16, 18, 26, 74, 50, 13, 38, 13, 79, 86, 86, 87]
KEYOUT = []
for X in PASS:
    KEYOUT.append((ord(X) + I ^ ord(KEY[I])) % 255)
    I = (I + 1) % len(KEY)

if SOLUCE == KEYOUT:
    print('You Win')
else:
    print('Try Again !')

any help !

mahmoudadel
  • 157
  • 1
  • 2
  • 11
  • This looks like a combination of [XOR cipher](https://en.wikipedia.org/wiki/XOR_cipher) (XOR on the flag and key characters) and [Caesar cipher](https://en.wikipedia.org/wiki/Caesar_cipher) (shift by `I`) so start your read there... – zwer Apr 05 '18 at 15:00
  • i am asking about whats really happening in the for loop and how to reverse i tried chr but not working – mahmoudadel Apr 05 '18 at 15:01
  • That's really easy task, I have trouble hinting without giving complete solution out. Please, elaborate what you tried and where you failed. Giving complete solution without solid evidence of your attempts is frowned upon on SO – Seer.The Apr 05 '18 at 15:05
  • 1
    Great read: [How to debug small programs (#1)](https://ericlippert.com/2014/03/05/how-to-debug-small-programs/) use a debugger or a lots of prints to display the steps to get behind what the code does... - like "what is ord(X) . what is I ^ ord(...) etc – Patrick Artner Apr 05 '18 at 15:06
  • Bruteforce in this case is surely an option. And it doesn't require Ruby. ;) – Jeronimo Apr 05 '18 at 15:19
  • @Seer.The Lets see your solution then... – Dave Carruthers Apr 05 '18 at 16:33

1 Answers1

0

There will be how I thought about this problem and complete solution.

  1. Notice len(KEYOUT) == len(PASS) == len(SOLUCE)
  2. Notice that there's no dependency between symbols
  3. So all you need is find such X that (ord(X) + I ^ ord(KEY[I])) % 255) is equal to corresponding element in SOLUCE

    FLAG = []
    for part in SOLUCE:
        for ord_X in range(0, 256):
            current_try = (ord_X + I ^ ord(KEY[I])) % 255
            if current_try == part:
                FLAG.append(chr(ord_X))
                break
        else:
            print("fiasco")  # if you aren't sure task is solvable. Not necessary line
        I = (I + 1) % len(KEY)
    

Validating is trivial.

Seer.The
  • 475
  • 5
  • 15