Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

12102040701140

Download as pdf or txt
Download as pdf or txt
You are on page 1of 27

Practical - 1

Aim: Study and perform practical on Cryptography algorithm for securing


data.
 Cryptography:
Cryptography is a technique of securing information and communications through the use of
codes so that only those persons for whom the information is intended can understand and
process it. Thus preventing unauthorized access to information. The prefix “crypt” means
“hidden” and the suffix “graphy” means “writing”. In Cryptography, the techniques that are
used to protect information are obtained from mathematical concepts and a set of rule-based
calculations known as algorithms to convert messages in ways that make it hard to decode
them. These algorithms are used for cryptographic key generation, digital signing, and
verification to protect data privacy, web browsing on the internet and to protect confidential
transactions such as credit card and debit card transactions.

 Types of Cryptography:

1. Symmetric Key Cryptography: It is an encryption system where the sender and receiver
of a message use a single common key to encrypt and decrypt messages. Symmetric Key
cryptography is faster and simpler but the problem is that the sender and receiver have to
somehow exchange keys securely. The most popular symmetric key cryptography systems
are Data Encryption Systems (DES) and Advanced Encryption Systems (AES).

Pratham G. Patel (12102040701140) Page | 1


 Implementation:
Code:
#include <iostream>
#include <iomanip>
#include <string>
#include <cryptopp/aes.h>
#include <cryptopp/modes.h>
#include <cryptopp/filters.h>

using namespace CryptoPP;


using namespace std;

int main() {
// Key and IV (Initialization Vector) for AES
byte key[AES::DEFAULT_KEYLENGTH] = {'k', 'e', 'y', '1', '2', '3', '4', '5', '6', '7', '8', '9', '
1', '0', '1', '1'};
byte iv[AES::BLOCKSIZE] = {'i', 'v', '1', '2', '3', '4', '5', '6', '7', '8', '9', '1', '0', '1', '1', '1'};

// Message to be encrypted
string plainText = "Hello, AES!";

// Encrypt using AES in CBC mode


CBC_Mode<AES>::Encryption encryptor(key, sizeof(key), iv);
StringSource(plainText, true, new StreamTransformationFilter(encryptor, new StringSink
(cipherText)));

// Display the encrypted message


cout << "Encrypted Text: ";
StringSource(cipherText, true, new HexEncoder(new StringSink(cout)));
cout << endl;

return 0;
}

Output:

Pratham G. Patel (12102040701140) Page | 2


2. Asymmetric Key Cryptography: In Asymmetric Key Cryptography, a pair of keys is used
to encrypt and decrypt information. A receiver’s public key is used for encryption and a
receiver’s private key is used for decryption. Public keys and Private keys are different.
Even if the public key is known by everyone the intended receiver can only decode it
because he alone knows his private key. The most popular asymmetric key cryptography
algorithm is the RSA algorithm.

 Implementation:
Code:
#include<iostream>
#include<math.h>
using namespace std;
// find gcd
int gcd(int a, int b) {
int t;
while(1) {
t= a%b;
if(t==0)
return b;
a = b;
b= t;
}
}
int main() {
//2 random prime numbers
double p = 13;
double q = 11;
double n=p*q;//calculate n
double track;
double phi= (p-1)*(q-1);//calculate phi
//public key
//e stands for encrypt
double e=7;
//for checking that 1 < e < phi(n) and gcd(e, phi(n)) = 1; i.e., e and phi(n) are coprime.

Pratham G. Patel (12102040701140) Page | 3


while(e<phi) {
track = gcd(e,phi);
if(track==1)
break;
else
e++;
}
//private key
//d stands for decrypt
//choosing d such that it satisfies d*e = 1 mod phi
double d1=1/e;
double d=fmod(d1,phi);
double message = 9;
double c = pow(message,e); //encrypt the message
double m = pow(c,d);
c=fmod(c,n);
m=fmod(m,n);
cout<<"Original Message = "<<message;
cout<<"\n"<<"p = "<<p;
cout<<"\n"<<"q = "<<q;
cout<<"\n"<<"n = pq = "<<n;
cout<<"\n"<<"phi = "<<phi;
cout<<"\n"<<"e = "<<e;
cout<<"\n"<<"d = "<<d;
cout<<"\n"<<"Encrypted message = "<<c;
cout<<"\n"<<"Decrypted message = "<<m;
return 0;
}

Output:

Pratham G. Patel (12102040701140) Page | 4


Practical - 2
Aim: Study and implement about Bitcoin Structure and Design.
 Bitcoin:

 Bitcoin is a cryptocurrency, a new kind of payment network and money. It was created
by a person or group, going by the username Satoshi Nakamoto, who posted a
whitepaper on a discussion board.

 Bitcoin operates without a financial system or government authorities. It can be used as


an alternative to fiat currencies or as an investment, utilizing peer-to-peer transfers on
a digital network that records and secures all transactions. This network is powered by
a blockchain, an open-source program that chains transaction histories to prevent
manipulation.

 Bitcoin makes money for investors through appreciation, the increase of an asset's
market value. There's a lot going on behind the scenes in the Bitcoin network, so here's
a detailed primer designed to help you further your understanding of this digital
phenomenon.

 The Blockchain Ledger:

 The Bitcoin network maintains a distributed public ledger that records the ownership
of all bitcoin, the native digital asset token of the network. New transactions are
grouped together into “blocks” and added sequentially to the network’s ongoing chain
of blocks — hence the term “blockchain.” The Bitcoin blockchain contains every block
since inception, stretching all the way back to the first block known as the “Genesis
Block.”

 Identical copies of the blockchain are hosted on computers around the world that run
the Bitcoin software. These computers are called "nodes." This design ensures that no
single entity is in control of the blockchain or protocol that governs it. Bitcoin's
distributed nature makes it decentralized and resistant to being controlled (or shut
down) by any government or central authority. Theoretically, all nodes that maintain a
complete copy of the blockchain — known as "full nodes" — would need to be
destroyed in order to erase the Bitcoin blockchain. No small task as there are even full
nodes floating above the earth in space!

Pratham G. Patel (12102040701140) Page | 5


 Peer-to-Peer Network Nodes:
 Nodes are a major part of blockchain-based protocols and the cornerstone of
decentralization, security, and transparency. There are several types of nodes on the
Bitcoin network. When a user connects to the Bitcoin network to send or receive
bitcoin, her computer acts as a node. Most nodes are known as light nodes, which
typically only download the more recent blockchain data needed to process and verify
new transactions. This minimal approach keeps light nodes running quickly and
efficiently without requiring too much computational or storage resources.

 Anatomy of a Block:
 Each Bitcoin block is limited in size to one megabyte of data. For “Segregated
Witness” (SegWit) blocks, transaction data is limited to one megabyte, whereas
signature data (aka witness) is segregated and limited to three megabytes. This keeps
the block size at one megabyte while increasing block space for transaction data.
 A block contains the following information:
A Block header:
1. Version number
2. Hash of the previous block header
3. Hash of the root of Merkle tree of all the transactions in the current block
4. Timestamp
5. Difficulty target of the current block (meaning how difficult the target hash will be to
find)
6. Nonce

 Bitcoin Forks
 A fork occurs when an existing blockchain splits into two different blockchains. This
happens when an update is made to a protocol that not all of the nodes adopt. There are
two types of forks that blockchains can experience; a soft fork, whereby old nodes and
new nodes are able to read both blockchains (compatible); and a hard fork, whereby old
nodes cannot read the new blockchain and vice versa (incompatible). Hard forks result
in two separate blockchains with distinct native digital asset tokens that are separate
and apart from each other.
 When updates are made to the Bitcoin protocol, individual nodes must determine if they
will upgrade and accept the new changes or not. If a constituent of nodes within the
network refuses to adopt the changes, then a hard fork results. Bitcoin has experienced
several forks of both kinds, including the Bitcoin Cash hard fork that occurred at block
661,647, the last common block between Bitcoin and Bitcoin Cash. The Bitcoin Cash
fork emanated from a disagreement in the Bitcoin community around block size.
Bitcoin Cash adopted a block size of eight megabytes to increase transaction
throughput, whereas Bitcoin kept a block size of one megabyte to foster greater node
participation and ensure decentralization.

Pratham G. Patel (12102040701140) Page | 6


 Implementation of Bitcoin:
1. Explore a bitcoin structure using the blockchain demo, which is implementation of
SHA algorithm.

2. After that, we have exploring the block using SHA-256 algorithm. In this we have
enter some data in transaction data and click on start mining.

Pratham G. Patel (12102040701140) Page | 7


3. After in next phase, we have understand about the blockchain and transaction.

Pratham G. Patel (12102040701140) Page | 8


4. In last, we have seen the working of Coinbase and understanding about the Merkle
tree.

Pratham G. Patel (12102040701140) Page | 9


Practical - 4
Aim: Study and Install Bitcoin Wallet.
 Introduction:
 Bitcoin was the first ever cryptocurrency, and therefore the first network to support
crypto wallets. The first wallet ever created belonged to Bitcoin’s founder, Satoshi
Nakamoto. The second wallet belonged to Hal Finney, a friend of his. When Nakamoto
sent Finney 10 Bitcoin as a test; no one knew the significance this technology would
have.
 However, since then, we’ve witnessed many advancements in the realm of both crypto
and crypto wallets— even for the oldest network Bitcoin. To explain, with time the
Bitcoin ecosystem has grown immensely. Today, Bitcoin wallets are much more
complex and capable than Satoshi’s first wallet.
 If you are new to crypto, you might be wondering how a Bitcoin wallet works, or
possibly, how you can set one up yourself. In this article, we’ll dive into all of those
specifics and much more. But before we get there, what is a Bitcoin wallet exactly?

 Bitcoin Wallet:
 In the simplest of terms, a Bitcoin wallet is something that allows you to hold, send,
receive, access, and manage Bitcoin (BTC). You can think of them much like the wallet
you carry around in your pocket apart from the underlying tech is a bit more
complicated.

 See, Bitcoin wallets don’t actually store Bitcoin. Your cryptocurrency is always stored
on the blockchain. Your Bitcoin wallet’s purpose is to generate and store private keys
that allow you to access and manage different Bitcoin accounts.

 Types of Bitcoin wallets


 As with physical wallets, Bitcoin wallets come in a range of styles, each offering a tradeoff
between convenient access and security against theft.

1. Mobile: Mobile wallets, like WazirX multi-cryptocurrency wallet and Exodus bitcoin
wallet are those that run as apps on phones, tablets and other mobile devices.

2. Web: Web-based wallets, like Guarda Bitcoin Wallet, store your coins through an
online third party. You can gain access to your coins and make transactions through
any device that lets you connect to the internet. These web-based wallets are frequently
associated with crypto exchanges that allow you to trade and store crypto all in one
place.

Pratham G. Patel (12102040701140) Page | 10


3. Desktop: Desktop wallets, like Guarda and Exodus, are programs you can download
onto a computer to store coins on your hard drive. This adds an extra layer of security
versus web and mobile apps because you aren’t relying on third-party services to hold
your coins. Still, hacks are possible because your computer is connected to the internet.

4. Hardware: Hardware wallets are physical devices, like a USB drive, that are not
connected to the web. These include Ledger Nano X Bitcoin Wallet and Trezor Model
T Bitcoin Wallet available in India. To make transactions, you first need to connect the
hardware wallet to the internet, either through the wallet itself or through another
device with internet connectivity. There is typically another password involved to
make the connection, which increases security but also raises the risk you may lock
yourself out of your crypto if you lose the password.

5. Paper Wallets: In a paper wallet, you print off your key, typically a QR code, on a
paper document. This makes it impossible for a hacker to access and steal the password
online, but then you need to protect the physical document.

 What is MetaMask?

 Public blockchains like Ethereum are the next evolution of Internet databases, and
MetaMask is the next evolution of the browser.

 MetaMask is a web browser extension and mobile app that allows you to manage your
Ethereum private keys. By doing so, it serves as a wallet for Ether and other tokens,
and allows you to interact with decentralized applications, or dapps. Unlike some
wallets, MetaMask keeps no information on you: not your email address, not your
password, and not your Secret Recovery Phrase or other private keys. You retain all
power over your crypto-identity.

 Installation of MetaMask Wallet in Brave Browser

1. Visit https://metamask.io/
2. Click “Download".
3. Click on "Install MetaMask for Chrome". Ignore the alarm bells that are ringing: the
reason it says "Chrome" here is because Brave is a Chromium-based browser and
shares the Web Store with Chrome itself.
4. In the Chrome Store that opens, click 'Add to Brave'.

Pratham G. Patel (12102040701140) Page | 11


5. In the popup that appears, click 'Add extension'.

Pratham G. Patel (12102040701140) Page | 12


6. After Installation, we have seen that, there are two option: first is create a new wallet
and second is import existing wallet, show we have click on create a new wallet.

7. After that, check in checkbox for terms and conditions and click on agree.

Pratham G. Patel (12102040701140) Page | 13


8. After that, for MetaMask wallet, we have created a new password.

9. After that click on secure my wallet, and we have seen that, wallet was created
successfully.

Pratham G. Patel (12102040701140) Page | 14


10. After that, we have seen, one account: sepoliaETH and explore it.

Pratham G. Patel (12102040701140) Page | 15


11. In last, right hand side, we have seen and explore different wallet functions such as
overview, tokens, NFTs, Games.

Pratham G. Patel (12102040701140) Page | 16


Pratham G. Patel (12102040701140) Page | 17
 Installation of Bitcoin core using Snap manager:
1. In this step, we will be updating the system using the APT manager. Execute the below
command in the terminal to update the system.

2. Step 2: As in this method, we are installing the application using Snap Manager, we will
first need to install Snap Manager on our system. So to install the Snap Manager on our
system, execute the below command in the Linux Terminal.

3. Once the installation of Snap Manager is done, we can install the Bitcoin Core application
using Snap Manager. Execute the below command to install the Bitcoin Core application
using Snap Manager.

Pratham G. Patel (12102040701140) Page | 18


4. After installation is done, we can verify the installation by checking the version of the
application. In the below screenshot, you can see that we have got the version of the
application as v24.0.1, which indicates that the installation is successful on our system.

5. To launch the application for usage, we can search the Bitcoin Core application in the All
Applications section. As shown in the below screenshot, we have got the icon of the
application that can be launched by clicking on it.

Pratham G. Patel (12102040701140) Page | 19


6. After clicking on the icon, we launched the application. User can create their wallet and
perform transactions of Sending and Receiving money.

7. After that, we have seen one window, which is indicated a current balance.

Pratham G. Patel (12102040701140) Page | 20


8. After that, exploring the functions of node window.

9. We have try to understand about the bitcoin send and bitcoin receive function.

Pratham G. Patel (12102040701140) Page | 21


10. In last, show some information about the node window and also show the connected
nodes.

Pratham G. Patel (12102040701140) Page | 22


11. After using remove command, bitcoin core was removed.

Pratham G. Patel (12102040701140) Page | 23


Practical - 9
Aim: Install IPFS locally on our machine, initialize your node, view the
nodes in network and add files and directories install Swarm and run any
test file.
 Introduction IPFS Desktop App
 IPFS Desktop bundles an IPFS node, file manager, peer manager, and content explorer
into a single, easy-to-use application.
 Use IPFS Desktop to get acquainted with IPFS without needing to touch the terminal
— or, if you're already experienced, use the powerful menubar/taskbar shortcuts
alongside the command line to make your IPFS workflow faster.
 If you already have an IPFS node on your computer, IPFS Desktop will act as a control
panel and file browser for that node. If you don't have a node, it'll install one for you.
And either way, IPFS Desktop will automatically check for updates.

 How IPFS Works

 In Web3 development, decentralization is a key. IPFS, or InterPlanetary File System,


is a decentralized protocol for storing and sharing files in a peer-to-peer network. It
was developed to address the limitations of traditional client-server-based systems,
which rely on a centralized infrastructure that can be slow, costly, and vulnerable to
single-point-of-failure attacks.

 At its core, IPFS works by breaking down files into smaller pieces called “blocks” and
storing them across multiple nodes in the network. This means that files are not stored
in a single location, but rather distributed across the network, making it highly resilient
to failure and censorship.

 Getting Started with IPFS


 Installing and setting up IPFS:
1. Download IPFS from the official website: https://ipfs.io/docs/install/
2. Install IPFS according to your operating system instructions
 Initialize IPFS using the following command in your terminal/command prompt:
1. ipfs init
2. This will generate a configuration file and a unique peer ID that identifies your node
in the IPFS network.

Pratham G. Patel (12102040701140) Page | 24


1. Files Screen.

Pratham G. Patel (12102040701140) Page | 25


2. Explore Screen.

3. Peers Screen

Pratham G. Patel (12102040701140) Page | 26


4. Setting Screen

Pratham G. Patel (12102040701140) Page | 27

You might also like