Python Forum
Simple Cryptography Capture the Flag - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: Homework (https://python-forum.io/forum-9.html)
+--- Thread: Simple Cryptography Capture the Flag (/thread-461.html)

Pages: 1 2


Simple Cryptography Capture the Flag - DrEastwood - Oct-12-2016

I don't really understand how I am supposed to change my code to work to print the proper flag out in the text.
The flag itself is 30 characters long. An example of what the flag would look like is: f l a g { e a s y _ p e a s y _ l e m o n _ s q u e e z y }

f = open("quad_radical.txt")

txt = f.read()

p = 0
count = 0
for i in range(30):
        p = count ** 2
        print txt[p]
        count = count + 1
The text file that I am looking through looks like this: 
Now I obviously can see the flag is in the beginning and it does up by a quadratic formula, but when I run the code I only get the "f" and "l" of flag. Please help. Sorry if my formatting is bad.


RE: Simple Cryptography Capture the Flag - sparkz_alot - Oct-12-2016

Are you looking for "flag" or the value of flag i.e.: flag = "easy_peezy_lemon_squeezy" within the text file?


RE: Simple Cryptography Capture the Flag - DrEastwood - Oct-12-2016

I'm looking for a string with "flag{something_in_here}" in the file


RE: Simple Cryptography Capture the Flag - ichabod801 - Oct-12-2016

Do you mean something like this?

text = 'A sentence with a flag{in it} somewhere.'
start = text.index('flag{') + 5
end = text.index('}', start + 1)
print(text[start:end])



RE: Simple Cryptography Capture the Flag - micseydel - Oct-12-2016

I would simplify your loop code (though still wrong) to
for i in range(30):
   p = i ** 2
   print txt[p],
If you think you need more variables, then you should describe for us what they're supposed to do or be for, because I tried a few things and I'm not sure what change needs to be made either.


RE: Simple Cryptography Capture the Flag - micseydel - Oct-12-2016

(Oct-12-2016, 09:41 PM)ichabod801 Wrote: Do you mean something like this?
"flag" doesn't appear in their input.


RE: Simple Cryptography Capture the Flag - wavic - Oct-12-2016

(Oct-12-2016, 09:49 PM)micseydel Wrote:
(Oct-12-2016, 09:41 PM)ichabod801 Wrote: Do you mean something like this?
"flag" doesn't appear in their input.

I don't see '}' either. Unless the key length is 122 symbols or something.


RE: Simple Cryptography Capture the Flag - micseydel - Oct-12-2016

(Oct-12-2016, 10:41 PM)wavic Wrote: I don't see '}' neither.
Damn that's a good point.


RE: Simple Cryptography Capture the Flag - wavic - Oct-12-2016

(Oct-12-2016, 10:42 PM)micseydel Wrote:
(Oct-12-2016, 10:41 PM)wavic Wrote: I don't see '}' neither.
Damn that's a good point.

Don't be hurry! I had to edit my post. I was wondering 'either' or 'neither' to use  :D


RE: Simple Cryptography Capture the Flag - ichabod801 - Oct-12-2016

Sorry, totally misunderstood the question.