Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
jvdsn
GitHub Repository: jvdsn/crypto-attacks
Path: blob/master/attacks/ctr/bit_flipping.py
2589 views
1
def attack(c, pos, p, p_):
2
"""
3
Replaces the original plaintext with a new plaintext at a position in the ciphertext.
4
:param c: the ciphertext
5
:param pos: the position to modify at
6
:param p: the original plaintext
7
:param p_: the new plaintext
8
:return: the modified ciphertext
9
"""
10
c_ = bytearray(c)
11
for i in range(len(p)):
12
c_[pos + i] = c[pos + i] ^ p[i] ^ p_[i]
13
14
return c_
15
16