-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtransposition.html
178 lines (167 loc) · 6.18 KB
/
transposition.html
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Transposition Techniques</title>
<link href="https://fonts.googleapis.com/css2?family=Poppins:wght@300;400;600&display=swap" rel="stylesheet">
<style>
body {
font-family: 'Poppins', sans-serif;
margin: 0;
padding: 0;
background: linear-gradient(135deg, #3a0ca3, #7209b7);
color: #fff;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
height: 100vh;
text-align: center;
}
h1 {
font-size: 3rem;
margin-bottom: 30px;
text-shadow: 1px 1px 5px rgba(0, 0, 0, 0.2);
color: #f1faee;
}
.container {
display: flex;
gap: 40px;
width: 80%;
max-width: 1300px;
}
.input-box {
background: #a29bfe;
padding: 30px;
border-radius: 10px;
box-shadow: 0 4px 15px rgba(0, 0, 0, 0.3);
transition: transform 0.3s ease;
width: 45%;
}
.input-box:hover {
transform: translateY(-5px);
}
.input-box h2 {
font-size: 1.8rem;
margin-bottom: 15px;
color: #fff;
}
.input-box p {
font-size: 1rem;
color: #f1faee;
margin-bottom: 20px;
}
.input-box input,
.input-box select {
width: 100%;
padding: 12px;
margin: 10px 0;
font-size: 1.1rem;
border-radius: 8px;
border: none;
outline: none;
background: #fff;
color: #333;
}
.input-box button {
padding: 12px 20px;
font-size: 1.1rem;
background-color: #7209b7;
color: #fff;
border: none;
border-radius: 8px;
cursor: pointer;
transition: background-color 0.3s;
}
.input-box button:hover {
background-color: #a29bfe;
}
.result-box {
background: #2d3436;
padding: 20px;
border-radius: 8px;
color: #fff;
font-size: 1.2rem;
margin-top: 20px;
text-align: left;
display: none;
}
footer {
position: absolute;
bottom: 20px;
font-size: 0.8rem;
color: rgba(255, 255, 255, 0.7);
}
</style>
</head>
<body>
<h1>Transposition Techniques</h1>
<div class="container">
<!-- Single Transposition Section (Left Side) -->
<div class="input-box">
<h2>Single Transposition</h2>
<p>A simple rearrangement of letters based on a fixed rule or key.</p>
<input type="text" id="inputMessage" placeholder="Enter message" />
<input type="text" id="singleKey" placeholder="Enter transposition key (numbers)" value="3,1,2" />
<button onclick="performSingleTransposition()">Encrypt Message</button>
<div id="singleResult" class="result-box"></div>
</div>
<!-- Double Transposition Section (Right Side) -->
<div class="input-box">
<h2>Double Transposition</h2>
<p>Applies two rounds of transposition for added security.</p>
<input type="text" id="inputMessageDouble" placeholder="Enter message" />
<input type="text" id="doubleKey1" placeholder="Enter first transposition key (numbers)" value="4,2,3,1" />
<input type="text" id="doubleKey2" placeholder="Enter second transposition key (numbers)" value="2,4,1,3" />
<button onclick="performDoubleTransposition()">Encrypt Message</button>
<div id="doubleResult" class="result-box"></div>
</div>
</div>
<footer>
<p>© 2024 Transposition Techniques | Created by Kiran Kumar K</p>
</footer>
<script>
function performSingleTransposition() {
const message = document.getElementById('inputMessage').value;
const key = document.getElementById('singleKey').value;
if (!message || !key) {
alert("Please enter both message and key.");
return;
}
const result = singleTransposition(message, key);
document.getElementById('singleResult').style.display = 'block';
document.getElementById('singleResult').innerHTML = `<strong>Encrypted Message:</strong> ${result}`;
}
function performDoubleTransposition() {
const message = document.getElementById('inputMessageDouble').value;
const key1 = document.getElementById('doubleKey1').value;
const key2 = document.getElementById('doubleKey2').value;
if (!message || !key1 || !key2) {
alert("Please enter both message and keys.");
return;
}
const result = doubleTransposition(message, key1, key2);
document.getElementById('doubleResult').style.display = 'block';
document.getElementById('doubleResult').innerHTML = `<strong>Encrypted Message:</strong> ${result}`;
}
function singleTransposition(message, key) {
let result = '';
key = key.split(',').map(Number); // Convert the key to an array of numbers
let rows = Math.ceil(message.length / key.length);
let paddedMessage = message.padEnd(rows * key.length, 'X'); // Add padding for even length
for (let i = 0; i < key.length; i++) {
for (let j = 0; j < rows; j++) {
result += paddedMessage[j * key.length + key.indexOf(i + 1)];
}
}
return result;
}
function doubleTransposition(message, key1, key2) {
let firstPass = singleTransposition(message, key1);
let secondPass = singleTransposition(firstPass, key2);
return secondPass;
}
</script>
</body>
</html>