Cs PBL File

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 13

Project-Based Learning Report

On
Credit card Encryption Decryption using RSA

Submitted in the partial fulfillment of the requirements


For Project-based learning in Cyber Security

in
Electronics & Communication Engineering
By
2014111034 Tushar Chaubey
2014111044 Sania Goyal
2014111045 Swastik Gupta

Under the guidance of the Course In-charge

Prof. Dhiraj M. Dhane

Department of Electronics & Communication Engineering

Bharati Vidyapeeth
(Deemed to be University)
College of Engineering,
Pune – 4110043

Academic Year: 2023-24


Bharati Vidyapeeth
(Deemed to be University)
College of Engineering,
Pune – 411043

DEPARTMENT OF ELECTRONICS & COMMUNICATION ENGINEERING

CERTIFICATE

Certified that the Project Based Learning report entitled, “Credit card Encryption Decryption
using RSA ” is work done by

2014111034 Tushar Chaubey


2014111044 Sania Goyal
2014111045 Swastik Gupta

in partial fulfillment of the requirements for the award of credits for Project Based Learning
(PBL) in Cyber Security of Bachelor of Technology Semester VII, in Electronics and
Communication.

Date: 25/10/2023

Prof. Dhiraj M. Dhane Dr. Arundhati A. Shinde

Course In-charge Professor & Head E.C.E


INDEX

Sr. No. Title Page No.

1 Description of problem statement 4-6

2 Code for the given problem statement 7-9

3 Result of Code Evaluation 10

4 Conclusion 11

5 Project Outcome 12

6 References 13
Description of Problem Statement

Credit card Encryption Decryption using RSA

RSA:

RSA (Rivest-Shamir-Adleman) is a widely used asymmetric encryption algorithm named after


its inventors, Ron Rivest, Adi Shamir, and Leonard Adleman. It is commonly used for securing
sensitive data transmission and digital signatures.

How RSA Works:

RSA involves the use of a pair of keys: a public key and a private key.

1. Public Key: This key is used for encryption and can be freely distributed. It consists of two
components: the modulus (n) and the public exponent (e). The modulus is a product of two large
prime numbers (p) and (q), and the public exponent (e) is usually a small prime number.

2. Private Key: This key is kept secret and is used for decryption. It also consists of two
components: the modulus (n) and the private exponent (d). The private exponent (d) is calculated
based on the prime factors of (n), (p), and (q), and the public exponent (e).

Encryption Process:

To encrypt a message (m) using RSA with a recipient's public key (e, n):

1. Convert the message into an integer (m) that is less than the modulus (n).
2. Compute the ciphertext (c) using the formula:

c = m^e mod n
This ciphertext (c) can be safely transmitted over insecure channels.

Decryption Process:

To decrypt the ciphertext (c) using RSA with the recipient's private key (d, n):

1. Compute the original message (m) using the formula:

m = c^d mod n

Key Properties:

1. One-Way Function: RSA encryption is easy to compute, but the reverse operation (finding the
original message from the ciphertext) is considered computationally infeasible without the
private key.

2. Asymmetric: RSA uses a pair of keys: one for encryption and one for decryption. Anything
encrypted with the public key can only be decrypted with the corresponding private key and vice
versa.

3. Security: The security of RSA relies on the difficulty of factoring the product of two large
prime numbers. As long as these prime numbers remain secret and sufficiently large, RSA
encryption is secure.

RSA is widely used in various applications such as secure communication, digital signatures,
and key exchange protocols. However, due to its computational intensity for long messages, it's
often used in combination with symmetric encryption algorithms for securing data efficiently.
Credit Card Encryption using RSA:

1. Key Generation:
- Generate a pair of RSA keys: a public key and a private key.
- The public key consists of `(e, n)`, where `e` is the public exponent and `n` is the modulus.
- The private key consists of `(d, n)`, where `d` is the private exponent and `n` is the modulus.
- The security of RSA relies on the mathematical properties of large prime numbers, so ensure
you use secure methods to generate these primes.

2. Credit Card Data Encryption:


- Obtain the recipient's public key (consisting of `e` and `n`).
- Convert the credit card number and any other sensitive information into a numerical format
(usually using padding and encoding techniques).
- Encrypt the numerical representation of the credit card information using the recipient's
public key and the RSA encryption formula:
ciphertext = (credit_card_number)^e mod n

Credit Card Decryption using RSA:

1. Credit Card Data Decryption:


- The recipient uses their private key (consisting of `d` and `n`) to decrypt the received
ciphertext.
- Decrypt the ciphertext using the RSA decryption formula:
decrypted_credit_card_number = (ciphertext)^d mod n
- Reverse any padding or encoding techniques applied during encryption to obtain the original
credit card number and sensitive information.
Code for encryption and decryption using RSA:
1.Code for Encryption and Decyption of Credit card using RSA-:
import sys
import chilkat
rsa = chilkat.CkRsa()
key = chilkat.CkPrivateKey()

success = key.LoadAnyFormatFile("rsaPrivateKey.key","")
if (success != True):
print(key.lastErrorText())
sys.exit()

keyXml = key.getXml()

success = rsa.ImportPublicKey(keyXml)
if (success != True):
print(rsa.lastErrorText())
sys.exit()

# Encrypt a VISA credit card number:


# 1234-5678-0000-9999
ccNumber = "1234567800009999"
CVV="342"
Name="Aditi"

usePrivateKey = False
rsa.put_EncodingMode("base64")
encryptedcc = rsa.encryptStringENC(ccNumber,usePrivateKey)
print("Encrypted:")
print(encryptedcc)

encryptedCVV = rsa.encryptStringENC(CVV,usePrivateKey)
print("Encrypted:")
print(encryptedCVV)

encryptedName = rsa.encryptStringENC(Name,usePrivateKey)
print("Encrypted:")
print(encryptedName)

# Now decrypt:
rsaDecryptor = chilkat.CkRsa()

rsaDecryptor.put_EncodingMode("base64")
success = rsaDecryptor.ImportPrivateKey(keyXml)

usePrivateKey = True
decryptedcc = rsaDecryptor.decryptStringENC(encryptedcc,usePrivateKey)
decryptedCVV = rsaDecryptor.decryptStringENC(encryptedCVV,usePrivateKey)
decryptedName = rsaDecryptor.decryptStringENC(encryptedName,usePrivateKey)

print("Decrypted:")
print(decryptedcc)

print("Decrypted:")
print(decryptedCVV)

print("Decrypted:")
print(decryptedName)

2. Code for generating Private key


from cryptography.hazmat.primitives.asymmetric import rsa
from cryptography.hazmat.primitives import serialization

# Generate an RSA private key


private_key = rsa.generate_private_key(
public_exponent=65537, # Common value for RSA
key_size=2048, # Adjust the key size as needed
)

# Serialize the private key to PEM format


private_pem = private_key.private_bytes(
encoding=serialization.Encoding.PEM,
format=serialization.PrivateFormat.TraditionalOpenSSL,
encryption_algorithm=serialization.NoEncryption()
)

# Save the private key to a file


with open("rsaPrivateKey.key", "wb") as key_file:
key_file.write(private_pem)
Output:

Figure 1:Output for Encryption and Decryption of Credit card


Conclusion

Hence, in this Project-Based Learning, on the topic- ‘Credit card encryption decryption using
RSA.’ we have studied about the RSA algorithm and about credit card encryption and decryption
and performed its code in Python programming language. Overall, the understanding was
developed, and all the related concepts were understood well and performed using Python
programming language.
Project Outcome

Here, in this Project-Based Learning, under Course Outcome 4 (CO4): Analyse and evaluate the
digital payment system security and remedial measures against digital payment frauds. The
concepts were understood and performed using Python.
References

[1] What Is RSA Algorithm and How Does It Work in Cryptography?, Simplilearn, accessed
21 October 2023,< https://www.simplilearn.com/tutorials/cryptography-tutorial/rsa-algorithm>

[2] Example-code, Chilkat Software Inc, Chicago, Illinois, accessed 21 October


2023,<https://www.example-code.com/python/rsa_encryptCreditCard.asp>

[3] JULIA KAGAN,Updated July 27, 2023,Credit Card Authentication: What It Is and How
It Works, Investopedia, Edmonton, Canada,accessed 23 October 2023,<
https://www.investopedia.com/terms/c/credit-card-authentication.asp#:~:text=Credit%20card
%20encryption%20is%20a,information%2C%20such%20as%20account%20numbers.&text=A
%20card%20recovery%20bulletin%20is,been%20replaced%20by%20newer%20methods.>

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy