0

I want to write a simple java program that reverses all the bytes of a file. It should corrupt the file by encoding and make it accesible after decoding. Is there something I need to be aware of?

I'm asking this because I wrote a program like that in the past and it didn't work, because after decoding the file was still corrupted. Is there something I have to keep in mind like a header portion of the file or something?

4
  • Have you tried actually comparing the contents of working original and non-working "decoded" files? (With a hex editor, for example?) Commented Aug 1, 2019 at 12:28
  • 1
    reverses all the bytes of a file Reverses the bytes in the file (first became last, second - pre-last, and so on...) or reverses bits in each separate byte? Is there something I need to be aware of? The most dangerous is "break in the middle".
    – Akina
    Commented Aug 1, 2019 at 12:30
  • @grawity a hex editor is a pretty good idea. Thanks for that! Commented Aug 1, 2019 at 12:35
  • Like @Akina said, despite whatever issues you are having, if you are not accounting for interruptions in the “encoding” and “decoding” process you will corrupt the file. What happens if you encode only half the file and the program crashes? Do you have a method of knowing where the program left off? Otherwise you’re screwed. You need to flip the bits, confirm the flip, then update a pointer with that position. Commented Aug 1, 2019 at 19:29

1 Answer 1

0

If I understand this question, you can try: certutil.exe

  • decode Hexadecimal:

    certutil -f -decodehex some_file.hex some_file_out.ext

  • encode Hexadecimal:

    certutil -f -decodehex some_file.ext some_file_out.hex

  • decode Base64:

    certutil -f -decode some_file.b64 some_file_out.ext

  • encode Base64:

    certutil -f -encode some_file.ext some_file_out.b64


  • For decode base64:

@echo off 

rem :: do some task #1 ::
rem :: do some task #2 ::
rem :: do some task #3 ::
rem :: ............... ::
rem :: do some task #n ::
rem :: ----------------::
rem :: decode (itself = %~f0) file in runtime 

2>nul >nul ( 
"%__appdir__%certutil.exe" -f -decode "%~f0" "%temp%\some_file_out_sample.txt"
) || goto :^(

rem :: do some another task #1 ::
rem :: do some another task #2 ::
rem :: do some another task #3 ::
rem :: ....................... ::
rem :: do some another task #n ::
rem :: ------------------------::

rem :: when finished :: 
exit /b

:^(
echo/Error decoding file & exit /b

-----BEGIN CERTIFICATE-----
IFRoaXMgaXMgZm9yIHNhbXBsZSBmaWxlIHRvIGVuY29kZS9kZWNvZGUNCg==
-----END CERTIFICATE-----

  • For decode hexadecimal:

@echo off 

rem :: do some task #1 ::
rem :: do some task #2 ::
rem :: do some task #3 ::
rem :: ............... ::
rem :: do some task #n ::
rem :: ----------------::
rem :: echo/ hexdecimal string to file in runtime and decode 

(
   echo/0000 20 54 68 69 73 20 69 73  20 66 6f 72 20 73 61 6d
   echo/0010 70 6c 65 20 66 69 6c 65  20 74 6f 20 65 6e 63 6f
   echo/0020 64 65 2f 64 65 63 6f 64  65 0d 0a

) > "%temp%\some_file.hex" && ( 
2>nul >nul %__appdir__%certutil.exe -f -decodehex "%temp%\some_file.hex" "%temp%\some_file_out_sample.log"
) || goto :^(

rem :: do some another task #1 ::
rem :: do some another task #2 ::
rem :: do some another task #3 ::
rem :: ....................... ::
rem :: do some another task #n ::
rem :: -----------------------::

rem :: when finished :: 
exit /b

:^(
echo/Error decoding file & exit /b

Note: the base64 string will decode the file: "some_file_out_sample.txt/.log" with that into file:

"This is for sample file to encode/decode"

3
  • Thanks for ur answer, but I am looking to encrypt my files myself. Hex and Base64 encoding is very obvious and not safe for encryption. I rather look for something like an explanation if files change themsleves dynamically or something like a header that gets corrupted if you change the bytes around it.. Commented Sep 10, 2019 at 17:51
  • @PaulErlenmeyer thank for your comment, well sorry i'm not good at English, but, you can to check files by hash SHA512, look this command: %__appdir__%\certutil -hashfile "%temp%\some_file.ext" SHA512
    – Io-oI
    Commented Sep 10, 2019 at 18:13
  • Gotta look into int thanks! Commented Sep 10, 2019 at 18:16

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .