-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added a new route for ciphers and updated the navigation bar. Impleme…
…nted Ceaser Cipher algorithm.
- Loading branch information
Showing
8 changed files
with
227 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
{ | ||
"Access Control": "Mechanisms that enforce access rights to resources.", | ||
"Active Attack": "An attack that attempts to alter system resources or affect their operation.", | ||
"Asymmetric Encryption Algorithms": "Encryption algorithms that use two related keys: a public key and a private key.", | ||
"Attack": "Any action that compromises the security of information.", | ||
"Authentication": "A process used to verify the identity of a user, process, or system.", | ||
"Authentication Exchange": "A mechanism to ensure the identity of an entity through information exchange.", | ||
"Authenticity": "The property that ensures the entity is who it claims to be.", | ||
"Availability": "Ensures that systems work promptly and service is not denied to authorized users.", | ||
"Block Cipher": "A symmetric encryption algorithm that operates on fixed-size blocks of data.", | ||
"Confidentiality": "Preserving authorized restrictions on information access and disclosure.", | ||
"Cryptographic Hash Function": "A function that turns variable text into a fixed-length value, useful in cryptographic algorithms.", | ||
"Cryptography": "A branch of mathematics dealing with the transformation of data for secure storage and transmission.", | ||
"Cybersecurity": "The practice of protecting systems, networks, and programs from digital attacks and unauthorized access.", | ||
"Data Authenticity": "Ensures the integrity and origin of data through verification.", | ||
"Data Confidentiality": "Ensures that data is not disclosed to unauthorized parties.", | ||
"Data Integrity": "Ensures that data remains accurate, consistent, and unaltered during processing and storage.", | ||
"Data Origin Authentication": "Ensures that the claimed source of information is authentic.", | ||
"Denial of Service": "An attack that makes a system or network unavailable to users." | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -31,4 +31,4 @@ html, body { | |
|
||
.card-back { | ||
transform: rotateY(180deg); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,140 @@ | ||
import React, { useState } from "react"; | ||
import "./ceaser-cipher.css"; // Import CSS for styling (you can create this file) | ||
|
||
const CaesarCipher = () => { | ||
const [message, setMessage] = useState(""); | ||
const [shift, setShift] = useState(0); | ||
const [encryptedMessage, setEncryptedMessage] = useState(""); | ||
const [animation, setAnimation] = useState([]); | ||
const [isEncrypting, setIsEncrypting] = useState(false); | ||
|
||
// Function to perform Caesar Cipher encryption | ||
const encrypt = (text, shift) => { | ||
return text | ||
.split("") | ||
.map((char) => { | ||
const code = char.charCodeAt(0); | ||
if (code >= 65 && code <= 90) { | ||
return String.fromCharCode(((code - 65 + shift) % 26) + 65); | ||
} else if (code >= 97 && code <= 122) { | ||
return String.fromCharCode(((code - 97 + shift) % 26) + 97); | ||
} else { | ||
return char; | ||
} | ||
}) | ||
.join(""); | ||
}; | ||
|
||
// Function to handle message change | ||
const handleChangeMessage = (e) => { | ||
if (!isEncrypting) { | ||
setMessage(e.target.value); | ||
} | ||
}; | ||
|
||
// Function to handle shift change | ||
const handleChangeShift = (e) => { | ||
setShift(parseInt(e.target.value)); | ||
}; | ||
|
||
// Function to animate the cipher transformation | ||
const animateCipher = () => { | ||
setIsEncrypting(true); | ||
setAnimation([]); // Reset animation array | ||
let animationArray = []; | ||
for (let i = 0; i < message.length; i++) { | ||
const char = message[i]; | ||
animationArray.push({ char, animated: false }); | ||
} | ||
setAnimation(animationArray); | ||
|
||
let encrypted = ""; | ||
for (let i = 0; i < message.length; i++) { | ||
const char = message[i]; | ||
const encryptedChar = encrypt(char, shift); | ||
setTimeout(() => { | ||
setAnimation((prevAnimation) => { | ||
const updatedAnimation = [...prevAnimation]; | ||
updatedAnimation[i].char = encryptedChar.toUpperCase(); | ||
updatedAnimation[i].animated = true; | ||
return updatedAnimation; | ||
}); | ||
}, i * 300); | ||
encrypted += encryptedChar; | ||
} | ||
setEncryptedMessage(encrypted.toUpperCase()); | ||
setTimeout(() => { | ||
setIsEncrypting(false); | ||
}, message.length * 300); | ||
}; | ||
|
||
// Function to handle clearing the fields | ||
const handleClear = () => { | ||
setMessage(""); | ||
setShift(0); | ||
setEncryptedMessage(""); | ||
setAnimation([]); | ||
setIsEncrypting(false); | ||
}; | ||
// JSX for the component | ||
return ( | ||
<div className="container-fluid mt-5 p-5 d-flex justify-content-center align-items-center flex-column"> | ||
<div className=""> | ||
<h2>Caesar Cipher</h2> | ||
<div className="text-end"> | ||
<div> | ||
<label>Message:</label> | ||
<input | ||
type="text" | ||
value={message} | ||
onChange={handleChangeMessage} | ||
disabled={isEncrypting} | ||
onKeyPress={(e) => { | ||
const charCode = e.charCode; | ||
if ( | ||
!(charCode >= 97 && charCode <= 122) && // a-z | ||
charCode !== 0 && | ||
!(charCode === 32) // Allow space | ||
) { | ||
e.preventDefault(); | ||
} | ||
}} | ||
/> | ||
</div> | ||
<div className=""> | ||
<label>Shift:</label> | ||
<input | ||
type="number" | ||
value={shift} | ||
disabled={isEncrypting} | ||
onChange={handleChangeShift} | ||
/> | ||
</div> | ||
</div> | ||
<div className="text-center p-2 d-flex justify-content-around"> | ||
<button onClick={animateCipher} disabled={isEncrypting}> | ||
Encrypt | ||
</button> | ||
<button onClick={handleClear} disabled={isEncrypting}> | ||
Clear | ||
</button> | ||
</div> | ||
</div> | ||
<div className="array-container w-100 d-flex justify-content-center border-top border-dark pt-5"> | ||
{animation.map((item, index) => ( | ||
<div | ||
key={index} | ||
className={`array-item ${item.animated ? "animated" : ""}`} | ||
> | ||
{item.char} | ||
</div> | ||
))} | ||
</div> | ||
<div> | ||
<h5>Encrypted Message: {encryptedMessage} </h5> | ||
</div> | ||
</div> | ||
); | ||
}; | ||
|
||
export default CaesarCipher; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
.array-container { | ||
display: flex; | ||
flex-wrap: wrap; | ||
margin-top: 20px; | ||
} | ||
|
||
.array-item { | ||
border: 1px solid black; | ||
padding: 5px; | ||
margin-right: 5px; | ||
margin-bottom: 5px; | ||
width: 30px; | ||
height: 30px; | ||
display: flex; | ||
align-items: center; | ||
justify-content: center; | ||
font-size: 16px; | ||
font-weight: bold; | ||
transition: background-color 0.5s ease; | ||
} | ||
|
||
.array-item.animated { | ||
background-color: lightgreen; | ||
} | ||
|