Professional Documents
Culture Documents
Secure Data Transmission Using Aes-Merged
Secure Data Transmission Using Aes-Merged
Secure Data Transmission Using Aes-Merged
Submitted by
SIDHIQ N S (LMC20CS064)
to
of
Bachelor of Technology
in
APRIL 2024
DECLARATION
We undersigned hereby declare that the project report “Secure Data Transmission using AES”,
submitted for partial fulfilment of the requirements for the award of degree of Bachelor of
Technology of the APJ Abdul Kalam Technological University, Kerala is a bonafide work done
by us under supervision of Ms. Betty P Justin, Assistant Professor, Department of CSE. This
submission represents our ideas in our own words and where ideas or words of others have
been included; we have adequately and accurately cited and referenced the original sources.
We also declare that we have adhered to ethics of academic honesty and integrity and have not
misrepresented or fabricated any data or idea or fact or source in our submission. We
understand that any violation of the above will be a cause for disciplinary action by the institute
and/or the University and can also evoke penal action from the sources which have thus not
been properly cited or from whom proper permission has not been obtained. This report has
not been previously formed the basis for the award of any degree, diploma or similar title of
any other University.
Place: Thiruvananthapuram
Date: 29/04/2024
KAILAS SHAJI
SIDHIQ N S
DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING
CERTIFICATE
This is to certify that the report entitled “SECURE DATA TRANSMISSION USING AES”
submitted by Sulaiman Mohamed Nazeer, Kailas Shaji, Sidhiq N S to the APJ Abdul Kalam
Technological University in partial fulfilment of the requirements for the award of the Degree
of Bachelor of Technology in Computer Science and Engineering is a bonafide record of the
mini project work carried out by him/her under my guidance and supervision. This report in
any form has not been submitted to any other University or Institute for any purpose.
ACKNOWLEDGEMENT
The project on the topic “Detection of Real-Time Deep-Fake Videos” was taken as a part
of the curriculum for the award of B. Tech degree in Computer Science Engineering.
At the outset, we thank almighty God for making our endeavour a success. We also express
our gratitude to Dr. Smitha J C, Head of Department for providing us with adequate
facilities, ways and means by which we were able to complete this project.
We express our sincere gratitude to our project coordinator Ms. Priya Sekhar and our
project guide Ms. Betty P Justin, Computer Science Department for constant support and
valuable suggestions without which the successful completion of this project would not
have been possible.
We express our immense please and thankfulness to all the teachers and staff of the
Department of Computer Science, LMCST for their cooperation and support. We would
also like to thank some of our seniors, who helped us in all ways they could when we were
stuck on important conjectures during this effort of ours.
Last but not the least, we thank all others, especially our classmates and our family
members who in one way or another helped us in the successful completion of this work.
ii
ABSTRACT
Several of cryptographic techniques are being used to preserve security and could be
classified as: symmetric and asymmetric.
TABLE OF CONTENTS
Contents Page No
ACKNOWLEDGEMENT i
ABSTRACT ii
LIST OF FIGURES iv
CHAPTER 1- INTRODUCTION 1
1.1 INTRODUCTION 1
1.1 OBJECTIVE 3
CHAPTER 3- METHODOLOGY 14
CHAPTER 4- DESIGN 19
5.1 MODULES 30
CHAPTER 7- CONCLUSION 37
7.1 CONCLUSION 37
REFERENCES 40
APPENDIX 41
iv
LIST OF FIGURES
No Title Page No
CHAPTER 1
INTRODUCTION
1.1 INTRODUCTION
Cryptography is the process of changing plain text into encrypted text and
encrypted text back to plain text. Cryptography in most literature is classified into
symmetric and asymmetric cryptography Advanced Encryption Standard (AES) is
one of the most popular symmetric cryptography encryptions with block cipher
structure. Every round within the secret writing method, contains four operations:
Sub Byte, Shift Rows, Mix Column and Add Round Key
The algorithm is capable to use key lengths of 128, 192 and 256 bits and
also, the range of rounds 10, 12 and 14 severally. AES has four stages for encrypting
and decrypting message. These are: Sub Bytes, Shift Rows, Mix Columns and Add
Round Key.
Symmetric Key Cryptography: In this approach, both the sender and receiver use
the same secret key to encrypt and decrypt messages. While it's efficient, the
challenge lies in securely sharing the key between the communicating parties.
holder of the corresponding private key can decrypt them. This method overcomes
the key distribution problem of symmetric key cryptography.
AES (Advanced Encryption Standard) stands as one of the most robust and
widely adopted cryptographic algorithms, serving as a cornerstone in securing
sensitive data across various applications. Its development emerged as a response
to the necessity for a more secure and efficient encryption standard than its
predecessors. Let’s delve into an introduction on AES and its significance in
cryptography.
In the late 20th century, the need for a stronger encryption standard became
apparent as older algorithms like DES (Data Encryption Standard) were becoming
vulnerable to advanced cryptanalysis techniques. In 1997, the U.S. National
Institute of Standards and Technology (NIST) initiated a competition to develop a
new encryption standard. This led to the selection of the Rijndael algorithm,
developed by Vincent Rijmen and Joan Daemen, as the AES in 2001.
AES is a symmetric-key algorithm, meaning the same key is used for both
encryption and decryption. It operates on fixed block sizes of data, typically 128
bits, and supports key lengths of 128, 192, or 256 bits, offering flexibility in
balancing security and performance.
tool in the modern digital landscape, where the protection of sensitive information
is paramount.
The encryption process with a dynamic S-box retains the fundamental steps
of AES but incorporates the dynamically generated substitution values. These
values are typically derived from the encryption key or other parameters, ensuring
that each encryption session utilizes a unique set of substitution values.
The integration of a dynamic S-box into AES enhances its suitability for
applications requiring high levels of security and adaptability. This includes secure
communication channels, data storage systems, and cryptographic protocols where
the ability to adjust encryption parameters dynamically can mitigate emerging
threats.
1.2 OBJECTIVE
Exploring S-box Dynamics: Investigate the concept of dynamic S-boxes and their
impact on encryption security. Analyze how dynamically generated substitution
values enhance the resilience of AES against cryptanalytic attacks.
Application Development: Integrate the AES algorithm with a dynamic S-box into
practical applications or use cases. Develop software tools or libraries that leverage
this enhanced encryption scheme to secure sensitive data in real-world scenarios.
Real-world Impact: Aim to create a project that not only serves as a learning
experience but also has practical applications and implications for cybersecurity.
Strive to develop encryption solutions that can enhance data security and privacy in
various domains, contributing to a safer digital ecosystem.
CHAPTER 2
LITERATURE REVIEW
Amina Msolli Abdel Hamid Helali Haythem Ameur Hassen Maaref. (2017). Secure
Encryption for Wireless Multimedia Sensors Network. 18. Retrieved from
www.ijacsa.thesai.org
Arnab Rahman Chowdhury, Junayed Mahmud, Abu Raihan Mostofa Kamal, Md.
Abdul Hamid, Member. (2018). MAES: Modified Advanced Encryption Standard
for Resource Constraint Environments IEEE.
Standard (AES) which meets the demand by formulating a novel equation for
constructing a square matrix in affine transformation phase of MAES and is
applicable for Resource Constraint Environments.
The main aim of the current research work is to reduce the complexity path
of AES (Advanced Encryption Standard) Encryption. Architecture of MixColumn
transformation has been optimized in this research work. Traditional methods of
MixColumn transformation methods have been realized and re-designed by
reducing the redundant logical functions. Verilog Hardware Description Language
(Verilog HDL) has been used to design the optimized MixColumn transformation
of AES Encryption. Further optimized MixColumn design has been incorporated
into AES Encryption with appropriate input points. Common Sub-expression
Elimination (CSE) algorithm is used in developed AES Encryption algorithm.
Mary James, Deepa S Kumar P. G Scholar (2016, March 03). An Optimized Parallel
Mix column and Sub bytes’ design in Lightweight Advanced Encryption Standard.
International Journal Computational Engineering Research (IJCER) ISSN.
In this paper, the analysis has been done based on the following metrics: [1].
i- Encryption time: The time taken to convert plaintext to ciphertext is encryption
time. Encryption time depends upon key size, plaintext block size and mode. In our
experiment, we have measured encryption time in milliseconds. Encryption time
affects performance of the system [3]. Encryption time must be less making the
system fast and responsive.
Multimedia data (text, audio, image, animation and video) have been widely
used in the past few years for advanced digital content transmission. With the
network technology focusing on Internet of Things (IoT) nowadays, the security of
the multimedia content has raised researchers' concerns. The exchange of digital
data over a network has exposed the multimedia data to various kinds of abuse such
as Brute-Force attacks, unauthorized access, and network hacking. Therefore, the
system must be safeguarded with an efficient media-aware security framework such
as encryption methods that make use of standard symmetric encryption algorithms,
which will be responsible for ensuring the security of the multimedia data. For the
encryption of electronic data, one of the most prominent cryptographic algorithms
is the Advanced Encryption Standard algorithm: A symmetric block cipher that was
established by the U.S. National Institute of Standards and Technology (NIST).
However, some of the challenges arising from the use of this algorithm are
computational overhead, use of a fixed S-Box (which is a point of weakness) and
pattern problems, which occur when handling more complex multimedia data such
as text, image and video. Many researchers have carried out research aiming at
Cyber Security has become rising issue in recent years where encryption is
one of solution and has an important role in data protection. Encryption algorithms
that widely used in information security are asymmetric and symmetric. Advanced
Encryption Standard (AES) is one of symmetric encryption that most used often
and the most secure encryption today. However, AES encryption has slow
computation. Our experiment shows that both of algorithm’s combination needs
3.045 milliseconds for 1024 bytes of data and increase 3-4 milliseconds for 2048
bytes of data and so on. This paper proposes a novelty method to improve AES
algorithm with Shift Row and S.Box modification for Mix Column transformation.
The result show that our optimization has reduced 3 milliseconds and continue to
increase as the number of bytes increases. Percentage average of the optimization
is 86.143%.
decryption process. It has been found that the AES is different from the data
encryption standard (DES). In AES, the block and key size can be chosen
independently from 128, 160, 192, 224, 256 bits whereas in case of DES it is 56
bits. AES differ from DES as it not uses the feistel network. In feistel structure, half
of the data block is generally used to modify the other half of the data block and
then these halves are swapped. In case of AES the entire data block is processed in
parallel during each round using substitutions and permutations. It has been found
that the symmetric cipher is divided into two categories: stream cipher and block
cipher.
In stream cipher, one symbol is generally used such as character or bit for
the encryption and decryption process. It consists of Plaintext stream, Ciphertext
stream and Key stream. Whereas, for block cipher encryption is done together with
the plaintext symbol of m (m > 1) by creating the same size ciphertext symbol
grouped together. From the definition, in a block cipher single key is generally used
for the encryption even if the key consists of the multiple values.
CHAPTER 3
METHODOLOGY
At its core, the Bit-Wise Reverse Transposition Rule involves the reversal
of bit positions within a binary representation of data. By systematically rearranging
the order of bits, the original data undergoes a transformation that renders it
unintelligible to unauthorized entities without the corresponding decryption key.
This transposition process follows a predefined rule set, dictating the sequence and
magnitude of bit reversals based on factors such as key parameters, encryption
rounds, or other configurable parameters.
One of the key advantages of the Bit-Wise Reverse Transposition Rule lies
in its simplicity and efficiency. Unlike more complex encryption techniques that
require significant computational resources and processing overhead, this method
can be implemented with minimal computational cost, making it suitable for
resource-constrained environments such as embedded systems or IoT devices.
Furthermore, its reliance on bitwise operations ensures high performance and
scalability, enabling seamless integration into diverse computing platforms and
architectures.
Despite its simplicity, the Bit-Wise Reverse Transposition Rule offers a high
level of security against unauthorized access and data breaches. The inherent
randomness introduced by the bitwise transposition process enhances the
cryptographic strength of the encryption scheme, making it resistant to brute-force
attacks and cryptanalytic techniques. Moreover, the reversible nature of the
transposition ensures that decrypted data retains its original integrity and structure,
facilitating seamless data recovery and transmission.
In conclusion, the Bit-Wise Reverse Transposition Rule represents a
compelling approach to data encryption, offering a balance of simplicity, efficiency,
and security. Its reliance on bitwise manipulation and systematic transposition
provides a robust foundation for safeguarding digital information in a wide range
of applications and use cases. As cybersecurity threats continue to evolve,
innovative encryption techniques like the Bit-Wise Reverse Transposition Rule
offer a promising solution for protecting sensitive data in an increasingly
interconnected and digitized world.
We have proposed efficient data encryption technique that can be named as
bitwise reversed transposition operation, which enhances data encryption speed of
AES algorithm by using bitwise reverse transposition, which remove the
complexity of addition and multiplication operations of the current mix column
1) Taking the 1st row elements of the input to the 1st column in the output, and
then interchanging _ 21 with _ 31 and reverse bit wise in the output.
2) Taking the 2nd row elements of the input to the 3rd column in the output,
and then interchanging _ 23 with _ 33 and reverse bit wise in the output.
3) Taking the 3rd row elements of the input to the 2 nd column in the output,
and then interchanging _ 22 and _ 32 and reverse bit wise in the output.
4) Taking the 4th row elements of the input to the 4th column in the output, and
then interchanging _ 24 and _ 34 and reverse bit wise in the output. This
method is not similar to the original AES and MAES design method. It
showed easy operation and better efficiency as compared to the existing mix
column of AES and MAES method. In this method we take an array.
CHAPTER 4
DESIGN
b. EE-AES encryption
Encryption Speed
AES Encryption:
2. **Initial Round Key Addition:** The plaintext is XORed with the initial round
key. This operation adds an additional layer of randomness to the plaintext and
prepares it for subsequent rounds of encryption.
- **SubBytes:** Each byte of the state matrix undergoes a byte substitution using
a predefined S-box lookup table.
- **ShiftRows:** The rows of the state matrix are shifted cyclically to the left by
different offsets.
- **MixColumns:** The columns of the state matrix are mixed using a matrix
multiplication operation.
- **Round Key Addition:** Each round key is XORed with the state matrix,
adding additional randomness to the data.
Sure, here are the steps for encrypting plaintext into ciphertext using AES
(Advanced Encryption Standard), M-AES (Masking AES), and EE-AES
(Evaluating Encryption with AES):
1. Masking: Apply a masking scheme to both the plaintext and the key to protect
against side-channel attacks. This involves XORing the plaintext and key with
random masks generated for each round.
2. Masked AES Encryption: Perform the AES encryption process using the masked
plaintext and key. Follow the same steps as AES encryption, but with the masked
inputs.
3. Output: The resulting ciphertext is obtained from the masked AES encryption
process.
DECRYPTION SPEED
2. Key Schedule: The key schedule algorithm in AES generates round keys from
the original encryption key, which are used during decryption. The efficiency of the
key schedule algorithm impacts the decryption speed, as generating round keys for
each decryption round adds computational overhead.
Other factors that can impact decryption speed in EE-AES include the size
of the encryption circuit, the choice of cryptographic parameters, and the hardware
platform used for computation. Optimizations such as parallelization, circuit
simplification, and hardware acceleration can help improve decryption speed in EE-
AES implementations.
1. **Encryption Module:**
2. **Decryption Module:**
3. **Key Management:**
- **API Design:** Define clear and well-documented APIs for interacting with
the encryption and decryption modules, specifying input/output formats, error
handling, and security considerations.
5. **Security Considerations:**
CHAPTER 5
WORKING DESCRPITION
5.1 MODULES
1.System
2.User
1. System: -
- The system ensures that AES encryption is performed securely and efficiently,
providing the necessary resources and mechanisms for encrypting and decrypting
data according to the AES specification.
- Additionally, the system may enforce security policies, access controls, and
auditing mechanisms to protect the confidentiality and integrity of encrypted data
and ensure compliance with regulatory requirements.
2. User:
- Users may perform various tasks related to AES encryption, such as:
- Users interact with the AES encryption system to achieve specific security
objectives, such as protecting sensitive information, ensuring secure
communication, or complying with regulatory requirements.
- User involvement is critical for the effective and secure operation of AES
encryption, as users are responsible for making key decisions and implementing
encryption practices that align with their security needs and operational
requirements.
While "system" and "user" may not be modules within the AES algorithm itself,
they play essential roles in the broader context of AES encryption, encompassing
the technical and human aspects of securely encrypting and decrypting data.
Together, they form a cohesive framework for implementing and managing AES
encryption within an organization or system environment.
❖ The working of the project is mainly based on frontend code and backend
code.
❖ Backend code uses Python language and frontend code use the combination
of HTML, CSS and JavaScript languages.
❖ The file name of the frontend code is index.html and the file name of the
backend code is app.py.
Backend (app.py)
Frontend (index.html)
❖ Frontend code is used to design the web page, which is created with the
help of IP Address (127.0.0.1:500).
• To convert plain text into cipher text we need to click on the start encryption
button or the Encrypt button on the top.
• By clicking on the encrypt button there will be a page shown with columns
to enter the key and the plain text.
• For eg we type the text as “HI, how are you” and set the key as
“Ilovemycountry..,,,”.
• By clicking on the submit answer button a 16 bit key forms and that key will
be the end users decryption key.
• On the next page it shows as “Give the encryption” on that column we have
to enter this 16 bit digits which is generated by S-box.
• And to the column down to the key box we have to enter the key we provided
(Ilovemycountry..,,).
• And click on the submit answer button.
• “HI HOW ARE YOU” is the text the text that was given for converting into
cipher text.
• And the “ilovemycountry” is given as the encrypting key and clicking the
submit answer.
Fig 5.2.3: Generated key and our key are entered to Decrypt
CHAPTER 6
• The encrypted text “HI HOW ARE YOU” has been decrypted as thus the output
is obtained.
CHAPTER 7
CONCLUSION
7.1 CONCLUSION
The project based on AES with a dynamic S-box for hiding ciphertext
represents a compelling endeavour at the forefront of cryptographic innovation,
aiming to enhance the security and resilience of data encryption techniques against
sophisticated adversaries. By introducing a dynamic S-box, the project explores a
novel approach to concealing ciphertext, leveraging the adaptability and variability
of dynamically generated substitution values. This innovative technique offers a
potent defense mechanism against cryptanalytic attacks, effectively obscuring the
encrypted data from unauthorized access and decryption attempts.
At the heart of the project lies the AES algorithm, a cornerstone of modern
cryptography renowned for its robust security and efficiency. By integrating a
dynamic S-box into the AES encryption process, the project endeavours to augment
the cryptographic strength of AES, mitigating vulnerabilities associated with static
S-boxes and enhancing the overall security posture of encrypted data. Through
meticulous design and implementation, the project aims to demonstrate the efficacy
and practicality of employing dynamic S-boxes in real-world encryption scenarios.
The project's objectives encompass various aspects of cryptographic
research and development, including algorithmic design, implementation, security
analysis, and performance evaluation. By elucidating the underlying principles of
AES with a dynamic S-box, the project seeks to deepen our understanding of
advanced encryption techniques and their applicability in securing sensitive
information across diverse domains. Furthermore, the project endeavours to
contribute to the broader cryptographic community by sharing insights, findings,
and best practices gleaned from the research process.
In addition to its technical merits, the project holds significant implications for
cybersecurity and data privacy, addressing pressing concerns surrounding the
confidentiality and integrity of digital communications and transactions. By
advancing the state-of-the-art in encryption technology, the project endeavours to
REFERENCES
[1] Amina Msolli Abdel Hamid Helali Haythem Ameur Hassen Maaref. (2017).
Secure Encryption for Wireless Multimedia Sensors Network.18. Retrieved
from www.ijacsa.thesai.org
[2] Arnab Rahman Chowdhury, Junayed Mahmud, Abu Raihan Mostofa Kamal,
Md. Abdul Hamid, Member. (2018). MAES: Modified Advanced Encryption
Standard for Resource Constraint Environments IEEE.
[4] M. Vaidehi and B. Justus Rabi. (2015, December). Enhanced Mix Column
Design for AES Encryption ISSN.
[5] Mary James, Deepa S Kumar P. G Scholar (2016, March 03). An Optimized
Parallel Mix column and Sub bytes’ design in Lightweight Advanced
Encryption Standard. International Journal Computational Engineering
Research (IJCER) ISSN, (25 – 26).
[6] Mohammed Nazeh Abdul Wahid, Abdulrahman Ali, Babak Esparham and
Mohamed Marwan, (2018, JUNE 22). A Comparison of Cryptographic
Algorithms: DES, 3DES, AES, RSA and Blowfish for Guessing Attacks
Prevention ISSN.
[7] Mustafa Emad Hameed (2018, October 20). Review on Improvement of
Advanced Encryption Standard (AES) Algorithm based on Time Execution,
Differential Cryptanalysis and Level of Security. Journal of
Telecommunication, Electronic and Computer Engineering. Retrieved from
https://www.researchgate.net/publication/323081584, Iraq
[8] Rizky Riyaldhia, et al, (2017., October 13-14). improvement of advanced
encryption standard algorithm with shift row. Elsevier B. V. Retrieved from
www.sciencedirect.com
APPENDIX
APPENDIX 2:CODING
!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-
to-fit=no">
<meta name="description" content="">
<meta name="author" content="">
<title>EE-AES Encryptor-Decryptor</title>
<link rel="stylesheet" href="static/css/bootstrap.min.css">
<link rel="stylesheet" href="static/css/unicons.css">
<link rel="stylesheet" href="static/css/owl.carousel.min.css">
<link rel="stylesheet" href="static/css/owl.theme.default.min.css">
<!-- MAIN STYLE -->
<link rel="stylesheet" href="static/css/tooplate-style.css">
</head>
<body>
<!-- MENU -->
<nav class="navbar navbar-expand-sm navbar-light">
<div class="container">
<a class="navbar-brand" href="/home"><i class='uil uil-user'></i> EE-AES
Encryptor-Decryptor</a>
<button class="navbar-toggler" type="button" data-toggle="collapse"
data-target="#navbarNav" aria-controls="navbarNav" aria-expanded="false"
aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
<span class="navbar-toggler-icon"></span>
<span class="navbar-toggler-icon"></span>
</button>
</div>
</nav>
<!-- CONTACT -->
<section class="contact py-5" id="contact">
<div class="container">
<div class="row">
<div class="col-lg-5 mr-lg-5 col-12">
<img src="static/images/OIP.jpg" class="img-fluid" alt="project image">
</div>
<div class="col-lg-6 col-12">
<div class="contact-form">
<h4 class="mb-4">Decrypted Text</h4>
<h6 class="mb-4">{{enc}}</h6>
</div>
</div>
</div>
</div>
</section>
<!-- FOOTER -->
<footer class="footer py-5">
<div class="container">
<div class="row">
<div class="col-lg-12 col-12">
<p class="copyright-text text-center">Copyright © 2024
Company Name . All rights reserved</p>
<p class="copyright-text text-center">Designed by <a
rel="nofollow">EE-AES Encryptor-Decryptor</a></p>
</div>
</div>
</div>
</footer>
<script src="static/js/jquery-3.3.1.min.js"></script>
<script src="static/js/popper.min.js"></script>
<script src="static/js/bootstrap.min.js"></script>
<script src="static/js/Headroom.js"></script>
<script src="static/js/jQuery.headroom.js"></script>
<script src="static/js/owl.carousel.min.js"></script>
<script src="static/js/smoothscroll.js"></script>
<script src="static/js/custom.js"></script>
</body>
</html>
Backend code(app.py)
import numpy as np
import random
import numpy as np
import math
global sbox
global inv_sbox
global x
def generate_sbox(u_in=3.9985):
m=10000
x=np.random.rand(m)
x[0]=0.02
u=u_in
x_hex=[float.hex(x[0])]
x[i]=u*x[i-1]*(1-x[i-1])
x_hex.append(float.hex(x[i]))
s=[]
s_b=[]
for i in range(len(x_hex)):
s.append(x_hex[i][5]+x_hex[i][6])
for i in range(len(s)):
if len(s_b)<256:
s_b.append(int(s[i],16))
return s_b
def getSBoxValue(num):
return sbox[num]
Rcon = [0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36,
0x6c, 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97,
0x35, 0x6a, 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72,
0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66,
0xcc, 0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02, 0x04,
0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d,
0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a, 0xd4, 0xb3,
0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd, 0x61,
0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a,
0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40,
0x80, 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc,
0x63, 0xc6, 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5,
0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f, 0x25, 0x4a,
0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb, 0x8d,
0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c,
0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35,
0x6a, 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4,
0xd3, 0xbd, 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc,
0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02, 0x04, 0x08,
0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d, 0x9a,
0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d,
0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd, 0x61, 0xc2,
0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a, 0x74,
0xe8, 0xcb ]
def getRconValue(num):
return Rcon[num]
def rotate(word):
return word[1:]+word[:1]
word = rotate(word)
for i in range(4):
word[i] = getSBoxValue(word[i])
return word
print(key)
currentSize = 0
rconIteration = 1
for j in range(size):
expandedKey[j] = key[j]
currentSize += size
t = expandedKey[currentSize-4:currentSize]
if currentSize % size == 0:
t = core(t, rconIteration)
rconIteration += 1
for m in range(4):
currentSize += 1
print(expandedKey)
return expandedKey
ar = []
i = start
j=0
ar.append(0)
ar[j] = ord(string[i])
j += 1
i += 1
return ar
def rowShift(s):
r=s.copy()
r[4:8]=s[5:8]+s[4:5]
r[8:12]=s[10:12]+s[8:10]
r[12:16]=s[15:16]+s[12:15]
return r
def bit_reverse_transposition(s):
r=[]
for i in s:
r.append(bit_reverse(i,8))
return r
global sbox
global inv_sbox
global x
if len(key) % 16:
return None
expanded_key=expandKey(key)
plaintext = []
iput = [0] * 16
output = []
ciphertext = [0] * 16
cipherOut = []
firstRound = True
if stringIn != None:
cipher_text=[]
cipher_text_temp=[]
for j in range(int(math.ceil(float(len(stringIn))/16))):
start = j*16
end = j*16+16
end = len(stringIn)
for l in range(10):
stage_result=[]
for f in range(16):
stage_result.append(getSBoxValue(plaintext[f] ^
expanded_key[f+(l*16)]))
stage_result=rowShift(stage_result)
#print(stage_result)
stage_result=bit_reverse_transposition(stage_result)
plaintext=stage_result
final_result=[]
for f in range(16):
final_result.append(getSBoxValue(plaintext[f]))
final_result=rowShift(final_result)
for f in range(16):
cipher_text_temp.append(final_result[f] ^ expanded_key[f+160])
cipher_text.append(cipher_text_temp)
text_enc=""
for i in cipher_text[0]:
text_enc=text_enc+chr(i)
return cipher_text_temp
def get_inverse_sbox(sbox):
inv_sbox=[0]*256
for i in range(256):
inv_sbox[sbox[i]]=i
return inv_sbox
def getInvSBoxValue(num):
global sbox
global inv_sbox
global x
return inv_sbox[num]
def in_shift_rows(s):
r=s.copy()
r[4:8]=s[7:8]+s[4:7]
r[8:12]=s[10:12]+s[8:10]
r[12:16]=s[13:16]+s[12:13]
return r
if len(key) % 16:
return None
expanded_key=expandKey(key)
if stringIn != None:
tt=[]
for j in range(int(math.ceil(float(len(stringIn))/16))):
plaintext = stringIn[j*16:j*16+16]
cipher_text_temp=[]
for f in range(16):
cipher_text_temp.append(plaintext[f] ^ expanded_key[f+160])
cipher_text_temp=in_shift_rows(cipher_text_temp)
plaintext=[]
for f in range(16):
plaintext.append(getInvSBoxValue(cipher_text_temp[f]))
for l in range(10):
plaintext=bit_reverse_transposition(plaintext)
plaintext=in_shift_rows(plaintext)
stage_result=[]
for f in range(16):
stage_result.append(getInvSBoxValue(plaintext[f]))
stage_result_t=[]
for f in range(16):
stage_result_t.append(stage_result[f] ^ expanded_key[f+((9-l)*16)])
plaintext=stage_result_t
for i in plaintext:
tt.append(i)
stage_result_f=[]
stage_result_final=""
for i in tt:
if i!=0:
stage_result_final=stage_result_final+chr(i)
return stage_result_final
def gen_cypherkey(inp):
ck=[]
for i in range(len(inp)):
ck.append(ord(inp[i]))
cypher_key=ck[len(inp)-16:len(inp)]
return cypher_key,ck[:len(inp)-16]
app = Flask(__name__)
app.secret_key = "super_secret_key"
@app.route('/')
@app.route('/home')
def home():
return render_template('index.html')
@app.route('/encryptpage', methods=['POST','GET'])
def encryptpage():
return render_template('question.html')
@app.route('/decryptpage')
def decryptpage():
return render_template('result.html')
@app.route('/eval2', methods=['POST','GET'])
def eval2():
global sbox
global inv_sbox
global x
ans = request.form['message']
key = request.form['key']
cypherkey,sbox_val=gen_cypherkey(key)
ans=ans.replace("[","")
ans=ans.replace("]","")
ans=ans.split(",")
outp=[]
for i in ans:
outp.append(int(i))
temp=0
for i in range(len(sbox_val)):
temp=temp+sbox_val[i]
u=float("3.9"+str(temp))
sbox=generate_sbox(u)
inv_sbox=get_inverse_sbox(sbox)
y=decrypt(outp,cypherkey)
return render_template('decryptedout.html',enc=y)
@app.route('/eval', methods=['POST','GET'])
def eval():
global sbox
global inv_sbox
global x
ans = request.form['message']
key = request.form['key']
cypherkey,sbox_val=gen_cypherkey(key)
temp=0
for i in range(len(sbox_val)):
temp=temp+sbox_val[i]
u=float("3.9"+str(temp))
sbox=generate_sbox(u)
inv_sbox=get_inverse_sbox(sbox)
x=encrypt(ans,cypherkey)
return render_template('encrptedout.html',enc=x)
if __name__ == '__main__
app.run(debug=True)