Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Assignment #11

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions K Chaitra/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
Steps to Compile and run the Java Code

=======================================================================

Step 1 : Write a program on the notepad and save it with .java extension(for example, DemoFile.java) .

Step 2 : open Command prompt.

Step 3 : Set the directory in which the .java file is saved.

Step 4 : Use the "javac" command to compile the Java program. It generates a .class file in the same folder. It also shows an error if any.

--> javac DemoFile.java

Step 5 : Use the "java" command to run the Java program.

--> java DemoFile


=======================================================================
30 changes: 30 additions & 0 deletions K Chaitra/Security-implications.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
Security Implications of Using Blockchain for Financial Transactions:

1. Immutability: The immutability of blockchain ensures that past transactions cannot be altered, providing a high level of security against fraudulent activities and unauthorized modifications.

2. Transparency: All participants in the network have access to the entire transaction history. This transparency can help prevent fraudulent activities and ensure accountability among participants.

3. Decentralization: The decentralized nature of blockchain reduces the risk of single points of failure, making it more resilient against cyberattacks and data breaches.A decentralized blockchain network distributes control and decision-making power among participants.

4. Cryptographic Security: Blockchain uses cryptographic techniques to secure transactions and ensure confidentiality, integrity, and authenticity. This includes hashing algorithms for block integrity and digital signatures for transaction authentication.

5. Reduced Intermediaries: Blockchain has the potential to eliminate or minimize intermediaries in financial transactions, reducing associated risks and costs.

6. Trustless Transactions: Blockchain enables trustless transactions, where parties do not need to trust a central authority. Instead, they rely on the consensus protocol and cryptographic proofs to verify transactions.

7. Consensus Mechanisms: The choice of consensus mechanism (e.g., Proof of Work, Proof of Stake) impacts the security and performance of the blockchain network. Each mechanism has its strengths and weaknesses, and the security implications may vary accordingly. The security and effectiveness of these mechanisms are crucial for preventing attacks and ensuring fair participation.

8. Smart Contract Security: Smart contracts, self-executing code on the blockchain, can have vulnerabilities that could lead to financial losses if exploited. Careful development, testing, and auditing of smart contracts are crucial for secure financial transactions.

9. Private Keys and Wallet Security: Users must protect their private keys and wallets diligently. Losing a private key can result in permanent loss of access to funds.

10. 51% Attack: In proof-of-work blockchains, a malicious entity controlling 51% or more of the network's computing power could potentially manipulate the chain. However, this is generally less feasible for well-established and widely adopted blockchains.

11. Regulatory Compliance: While blockchain offers enhanced security, financial institutions using blockchain for transactions must also comply with existing regulations, including anti-money laundering (AML) and know-your-customer (KYC) requirements.

12. Scalability and Performance: As the number of transactions increases, scalability and performance become critical. High transaction fees or slow confirmation times could impact the usability and attractiveness of blockchain for financial transactions.

13. Upgrades and Forks: Blockchain networks may undergo upgrades or forks, which could introduce new security considerations and risks during the transition.


In conclusion, blockchain technology has the potential to revolutionize financial transactions by providing security, transparency, and decentralization. However, proper implementation, continuous security audits, and adherence to regulatory requirements are essential for realizing its full potential in the financial sector. As with any technology, careful consideration of the specific use case and understanding the security implications are crucial for successful and secure blockchain adoption.
114 changes: 114 additions & 0 deletions K Chaitra/app.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
package startproject;

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.ArrayList;
import java.util.List;

class Transaction {
String sender;
String receiver;
double amount;
long timestamp;

public Transaction(String sender, String receiver, double amount) {
this.sender = sender;
this.receiver = receiver;
this.amount = amount;
this.timestamp = System.currentTimeMillis();
}
}

class Block {
int indexValue;
String previoushashKey;
List<Transaction> transactions;
String hashKey;
long timestamp;

public Block(int indexValue, String previoushashKey, List<Transaction> transactions) {
this.indexValue = indexValue;
this.previoushashKey = previoushashKey;
this.transactions = transactions;
this.timestamp = System.currentTimeMillis();
this.hashKey = calculatehashKey();
}

String calculatehashKey() {
try {
MessageDigest digest = MessageDigest.getInstance("SHA-256");
String data = indexValue + previoushashKey + transactions.toString() + timestamp;
byte[] hashKeyBytes = digest.digest(data.getBytes());

StringBuilder hexString = new StringBuilder();
for (byte hashKeyByte : hashKeyBytes) {
String hex = Integer.toHexString(0xff & hashKeyByte);
if (hex.length() == 1) hexString.append('0');
hexString.append(hex);
}

return hexString.toString();
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
return null;
}
}
}

class Blockchain {
private List<Block> chain;

public Blockchain() {
chain = new ArrayList<>();
chain.add(createGenesisBlock());
}

private Block createGenesisBlock() {
return new Block(0, "0", new ArrayList<>());
}

public Block getLatestBlock() {
return chain.get(chain.size() - 1);
}

public void addBlock(List<Transaction> transactions) {
int indexValue = chain.size();
String previoushashKey = getLatestBlock().hashKey;

Block newBlock = new Block(indexValue, previoushashKey, transactions);
chain.add(newBlock);
}

public boolean isValid() {
for (int i = 1; i < chain.size(); i++) {
Block currentBlock = chain.get(i);
Block prevBlock = chain.get(i - 1);

if (!currentBlock.hashKey.equals(currentBlock.calculatehashKey()) ||
!currentBlock.previoushashKey.equals(prevBlock.hashKey)) {
return false;
}
}
return true;
}
}

public class HugoByteBlockChain {

public static void main(String[] args) {
Blockchain blockchain = new Blockchain();

List<Transaction> transactions = new ArrayList<>();
transactions.add(new Transaction("Chaitra", "Harish", 20.0));
transactions.add(new Transaction("Harish", "Sunil", 5.0));
transactions.add(new Transaction("Sunil", "Chaitra", 3.0));

blockchain.addBlock(transactions);

if (blockchain.isValid()) {
System.out.println("Blockchain is valid.");
} else {
System.out.println("Blockchain is not valid.");
}
}
}