<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://wiki.hacks.guide/w/index.php?action=history&amp;feed=atom&amp;title=User%3AIhaveahax%2FOTP_bitflip_finder</id>
	<title>User:Ihaveahax/OTP bitflip finder - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.hacks.guide/w/index.php?action=history&amp;feed=atom&amp;title=User%3AIhaveahax%2FOTP_bitflip_finder"/>
	<link rel="alternate" type="text/html" href="https://wiki.hacks.guide/w/index.php?title=User:Ihaveahax/OTP_bitflip_finder&amp;action=history"/>
	<updated>2026-05-17T04:30:52Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.43.8</generator>
	<entry>
		<id>https://wiki.hacks.guide/w/index.php?title=User:Ihaveahax/OTP_bitflip_finder&amp;diff=5040&amp;oldid=prev</id>
		<title>Ihaveahax: Created page with &quot;This was used to find a bitflip in an OTP in mid 2021. It goes through each bit of the encrypted OTP, flips it, decrypts, and verifies hashes. It only checks keydata, though, it could be modified to check the entire OTP.  == check.py == &lt;syntaxhighlight lang=&quot;python&quot;&gt; from pyctr.crypto import CryptoEngine from Cryptodome.Cipher import AES from hashlib import sha256  a = CryptoEngine()  with open(&#039;otp_dec.bin&#039;, &#039;rb&#039;) as f:     beginning = f.read(0x90)  with open(&#039;otp.bin&#039;...&quot;</title>
		<link rel="alternate" type="text/html" href="https://wiki.hacks.guide/w/index.php?title=User:Ihaveahax/OTP_bitflip_finder&amp;diff=5040&amp;oldid=prev"/>
		<updated>2023-12-21T05:57:18Z</updated>

		<summary type="html">&lt;p&gt;Created page with &amp;quot;This was used to find a bitflip in an OTP in mid 2021. It goes through each bit of the encrypted OTP, flips it, decrypts, and verifies hashes. It only checks keydata, though, it could be modified to check the entire OTP.  == check.py == &amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt; from pyctr.crypto import CryptoEngine from Cryptodome.Cipher import AES from hashlib import sha256  a = CryptoEngine()  with open(&amp;#039;otp_dec.bin&amp;#039;, &amp;#039;rb&amp;#039;) as f:     beginning = f.read(0x90)  with open(&amp;#039;otp.bin&amp;#039;...&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;This was used to find a bitflip in an OTP in mid 2021. It goes through each bit of the encrypted OTP, flips it, decrypts, and verifies hashes. It only checks keydata, though, it could be modified to check the entire OTP.&lt;br /&gt;
&lt;br /&gt;
== check.py ==&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
from pyctr.crypto import CryptoEngine&lt;br /&gt;
from Cryptodome.Cipher import AES&lt;br /&gt;
from hashlib import sha256&lt;br /&gt;
&lt;br /&gt;
a = CryptoEngine()&lt;br /&gt;
&lt;br /&gt;
with open(&amp;#039;otp_dec.bin&amp;#039;, &amp;#039;rb&amp;#039;) as f:&lt;br /&gt;
    beginning = f.read(0x90)&lt;br /&gt;
&lt;br /&gt;
with open(&amp;#039;otp.bin&amp;#039;, &amp;#039;rb&amp;#039;) as f:&lt;br /&gt;
    f.seek(0x80)&lt;br /&gt;
    iv = f.read(0x10)&lt;br /&gt;
    remaining = f.read()&lt;br /&gt;
&lt;br /&gt;
ints = bytearray(remaining)&lt;br /&gt;
for x in range(len(remaining)):&lt;br /&gt;
    orig = ints[x]&lt;br /&gt;
    for bit in range(8):&lt;br /&gt;
        new = orig ^ (1 &amp;lt;&amp;lt; bit)&lt;br /&gt;
        ints[x] = new&lt;br /&gt;
        cipher = AES.new(a.otp_key, AES.MODE_CBC, iv)&lt;br /&gt;
        data = cipher.decrypt(ints)&lt;br /&gt;
        before_hash = data[0:0x50]&lt;br /&gt;
        ohash = data[0x50:]&lt;br /&gt;
        hash_before_hash = sha256(beginning + before_hash).hexdigest()&lt;br /&gt;
        print(x, bit, hash_before_hash, ohash.hex(), hash_before_hash == ohash.hex())&lt;br /&gt;
        if hash_before_hash == ohash.hex():&lt;br /&gt;
            print(beginning + before_hash + ohash)&lt;br /&gt;
    ints[x] = orig&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;/div&gt;</summary>
		<author><name>Ihaveahax</name></author>
	</entry>
</feed>