0

i have to write a scrypt (for a university class and i must send to proffesor until sunday) that will crack a pdf file, i have tryied a lot so far but cant make it work my code is:

#!/usr/bin/python2.7
from PyPDF2 import PdfFileReader, PdfFileWriter
import logging
import time

t=time.localtime()

t1=time.asctime(t)
log_filename='pass_found.log'
logging.basicConfig(filename=log_filename,level=logging.INFO)
output = PdfFileWriter()
pdf = PdfFileReader(file( "sf.pdf", "rb"))
f=open('datepass.txt')   
content=f.readlines()
words=[x.strip() for x in content]
  for i in words:
       if (pdf.decrypt(i) == 1) or (pdf.decrypt(i) == 2):
             logging.info('{0} :o kodikos einai "{1}"'.format(t1,i))

datepass is a txt that contains date passwords(DD-MM-YY-> date-month-year)

Martin Thoma
  • 124,992
  • 159
  • 614
  • 958
dimargy
  • 1
  • 1
  • 1
    Can you please explain what you mean by 'crack a pdf'? What information do you want to extract. What errors do you see when you try and run the above code? – Mike Oct 31 '14 at 20:52
  • i dont have errors it doesnt work or return any i.... – dimargy Oct 31 '14 at 20:54
  • our prof said its password protected and we have to open it with a python scrypt. the form of the password is DD-MM-YYYY – dimargy Oct 31 '14 at 20:55
  • 2
    Create a test case to see if your code works: a PDF with a known password (one in `datepass.txt`). If this works, your password is not in that file. – Jongware Oct 31 '14 at 22:57
  • i have every date from 00-00-0000 to 31-12-2015 – dimargy Nov 01 '14 at 11:21
  • How do you know the password isn't any later than 31-12-2015? If you can go all the way back to 00-00-0000 (shouldn't that be 01-01-0000?) why not go up until 31-12-9999? Jongware had the best suggestion, though. Since we don't know what the real password is, your code may very will be working just fine. You need to create a test case for yourself where you know the password, and see if your code finds it. – skrrgwasme Nov 01 '14 at 15:44
  • #!/usr/bin/python3 from PyPDF2 import PdfFileReader, PdfFileWriter pdf=PdfFileReader(file( "sf.pdf", "rb")) f=open('datepass.txt') content=f.readlines() words=[x.strip() for x in content] for i in words: try: a=pdf.decrypt(i) if a==1: with open("datefound.txt", "w") as text_file: text_file.write(i) except: pass – dimargy Nov 02 '14 at 13:25

0 Answers0