| 49 | return data |
| 50 | |
| 51 | def main(): |
| 52 | usage = '%s [-d] -i <input file> [-o <output file>]' % sys.argv[0] |
| 53 | parser = OptionParser(usage=usage, version='0.2') |
| 54 | |
| 55 | try: |
| 56 | parser.add_option('-d', dest='decrypt', action="store_true", help='Decrypt') |
| 57 | parser.add_option('-i', dest='inputFile', help='Input file') |
| 58 | parser.add_option('-o', dest='outputFile', help='Output file') |
| 59 | |
| 60 | (args, _) = parser.parse_args() |
| 61 | |
| 62 | if not args.inputFile: |
| 63 | parser.error('Missing the input file, -h for help') |
| 64 | |
| 65 | except (OptionError, TypeError) as ex: |
| 66 | parser.error(ex) |
| 67 | |
| 68 | if not os.path.isfile(args.inputFile): |
| 69 | print('ERROR: the provided input file \'%s\' is non existent' % args.inputFile) |
| 70 | sys.exit(1) |
| 71 | |
| 72 | if not args.decrypt: |
| 73 | data = cloak(args.inputFile) |
| 74 | else: |
| 75 | data = decloak(args.inputFile) |
| 76 | |
| 77 | if not args.outputFile: |
| 78 | if not args.decrypt: |
| 79 | args.outputFile = args.inputFile + '_' |
| 80 | else: |
| 81 | args.outputFile = args.inputFile[:-1] |
| 82 | |
| 83 | f = open(args.outputFile, 'wb') |
| 84 | f.write(data) |
| 85 | f.close() |
| 86 | |
| 87 | if __name__ == '__main__': |
| 88 | main() |