forked from librauee/Steganalysis
-
Notifications
You must be signed in to change notification settings - Fork 0
/
F4.py
67 lines (54 loc) · 1.94 KB
/
F4.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# -*- coding: utf-8 -*-
"""
Created on Tue Jun 11 16:10:51 2019
@author: Administrator
"""
from Jsteg import Jsteg
class F4(Jsteg):
def __init__(self):
Jsteg.__init__(self)
def set_sequence_after_dct(self,sequence_after_dct):
self.sequence_after_dct=sequence_after_dct
sum_len=len(self.sequence_after_dct)
zero_len=len([i for i in self.sequence_after_dct if i==0])
one_len=len([i for i in self.sequence_after_dct if i in (-1,1)])
self.available_info_len=sum_len-zero_len-one_len # 不是特别可靠
print ("Load>> 大约可嵌入",sum_len-zero_len-int(one_len/2),'bits')
print ("Load>> 最少可嵌入",self.available_info_len,'bits\n')
def _write(self,index,data):
origin=self.sequence_after_dct[index]
if origin == 0:
return False
elif origin == 1 and data==0:
self.sequence_after_dct[index]=0
return False
elif origin == -1 and data==1:
self.sequence_after_dct[index]=0
return False
lower_bit=origin%2
if origin >0:
if lower_bit!=data:
self.sequence_after_dct[index]=origin-1
else:
if lower_bit==data:
self.sequence_after_dct[index]=origin+1
return True
def _read(self,index):
if self.sequence_after_dct[index] >0:
return self.sequence_after_dct[index]%2
elif self.sequence_after_dct[index]<0:
return (self.sequence_after_dct[index]+1)%2
else:
return None
if __name__=="__main__":
f4=F4()
# 写
sequence_after_dct=[-1,0,1]*100+[i for i in range(-7,500)]
f4.set_sequence_after_dct(sequence_after_dct)
info1=[0,1,0,1,1,0,1,0]
f4.write(info1)
# 读
sequence_after_dct2=f4.get_sequence_after_dct()
f4.set_sequence_after_dct(sequence_after_dct2)
info2=f4.read()
print (info2)