pifs
pifs copied to clipboard
Is there an automated tool to decrypt the metadata?
So unfortunately, I lost main main data drive, but the good news is I have it all backed up with πfs. Unfortunately I am not math-savvy enough to implement the Bailey–Borwein–Plouffe formula to restore the data myself. Surely someone must have made a tool by now?
import struct
import math
import sys
import os
def get_byte(id):
def series(m, id):
s = 0
for k in range(id):
ak = 8 * k + m
p = id - k
t = pow(16, p, ak) / ak
s += t
s = s - int(s)
for k in range(id, id + 101):
ak = 8 * k + m
t = 16 ** (id - k) / ak
if t < 1e-17:
break
s += t
s = s - int(s)
return s
s1 = series(1, id)
s2 = series(4, id)
s3 = series(5, id)
s4 = series(6, id)
pid = 4 * s1 - 2 * s2 - s3 - s4
pid = pid - int(pid) + 1
y = abs(pid)
y = 16 * (y - math.floor(y))
first = int(y)
y = 16 * (y - math.floor(y))
second = int(y)
return (first << 4) | second
def decode_from_pi_positions(metadata_file, output_file):
try:
with open(metadata_file, 'rb') as file:
positions = struct.unpack(f'{os.path.getsize(metadata_file) // 2}h', file.read())
decoded_bytes = bytearray()
for position in positions:
pi_byte = get_byte(position)
decoded_bytes.append(pi_byte)
with open(output_file, 'wb') as file:
file.write(decoded_bytes)
return f"File successfully decoded and saved as '{output_file}'"
except FileNotFoundError:
return f"Error: File '{metadata_file}' not found."
except PermissionError:
return f"Error: Permission denied when trying to read '{metadata_file}' or write '{output_file}'."
except Exception as e:
return f"Error decoding: {str(e)}"
if __name__ == "__main__":
if len(sys.argv) != 3:
print("Usage: python script_name.py <path_to_metadata_file> <path_to_output_file>")
sys.exit(1)
metadata_file_path = sys.argv[1]
output_file_path = sys.argv[2]
result = decode_from_pi_positions(metadata_file_path, output_file_path)
print(result)
@alberto98fx