<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Jyotirmoy Barman</title>
    <description>The latest articles on DEV Community by Jyotirmoy Barman (@jyotirmoydotdev).</description>
    <link>https://dev.to/jyotirmoydotdev</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F756958%2Fbaa66b7b-c695-4a6b-9fb6-8ddc3ffd5e3e.jpg</url>
      <title>DEV Community: Jyotirmoy Barman</title>
      <link>https://dev.to/jyotirmoydotdev</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/jyotirmoydotdev"/>
    <language>en</language>
    <item>
      <title>Blockchain Storage</title>
      <dc:creator>Jyotirmoy Barman</dc:creator>
      <pubDate>Mon, 27 Feb 2023 18:05:21 +0000</pubDate>
      <link>https://dev.to/jyotirmoydotdev/blockchain-storage-50kj</link>
      <guid>https://dev.to/jyotirmoydotdev/blockchain-storage-50kj</guid>
      <description>&lt;p&gt;To understand the storage system on blockchain we need to first understand &lt;strong&gt;what we store in the blockchain.&lt;/strong&gt; My previous &lt;a href="https://jyotirmoy.dev/blockchain-structure"&gt;Blockchain Structure&lt;/a&gt; explains this.&lt;/p&gt;

&lt;p&gt;%[&lt;a href="https://jyotirmoy.dev/blockchain-structure"&gt;https://jyotirmoy.dev/blockchain-structure&lt;/a&gt;] &lt;/p&gt;

&lt;h1&gt;
  
  
  Introduction to blockchain storage
&lt;/h1&gt;

&lt;p&gt;The blockchain contains some data, such as transactions or other information, and a unique code, called a hash, hash is generated based on the contents of the block. The hash is used to identify the block and ensure its integrity.&lt;/p&gt;

&lt;p&gt;One of the popular blockchains is Ethereum, it can store data, including images, but it is not an ideal storage solution for large files due to the limited storage capacity and high cost of storing data on the blockchain. Whenever the data size of the Ethereum chain reaches 1 Tb pruned happens, Pruning is &lt;strong&gt;the process of erasing older data to save disk space&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://etherscan.io/chartsync/chaindefault"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s---4ExDRlX--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn.hashnode.com/res/hashnode/image/upload/v1677349501595/fe60a62a-13b6-4eee-b162-2c8070b10191.png%3Fauto%3Dcompress%2Cformat%26format%3Dwebp" width="800" height="461"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;However, there are some ways to store files on the Ethereum network. One standard method is to use IPFS (InterPlanetary File System), a decentralized storage system that allows for the efficient and secure distribution of files. IPFS can be used to store files and other large documents off-chain, while the file hash is stored on the Ethereum blockchain, ensuring that the data is tamper-proof and publicly verifiable.&lt;/p&gt;

&lt;h1&gt;
  
  
  Traditional storage vs blockchain storage
&lt;/h1&gt;

&lt;p&gt;Traditional storage systems rely on a centralized server or data center to store and manage data. This centralized approach makes the data vulnerable to attacks, data breaches, and censorship, as well as more costly to manage and maintain. Centralized systems also require users to trust the centralized authority to manage their data, which can lead to issues with privacy, security, and control. Suppose a company has a data server, which is located in XYZ location if there is a natural disaster, then there is a risk of data loss.&lt;/p&gt;

&lt;p&gt;On the other hand, blockchain storage uses a decentralized and distributed network of nodes to store and share data. This makes the data more secure, transparent, auditable, and more efficient and cost-effective to manage. Users have more control over their data, as they can store it themselves or choose who to share it with, without relying on a centralized authority.&lt;/p&gt;

&lt;h1&gt;
  
  
  Decentralized storage and its benefits
&lt;/h1&gt;

&lt;p&gt;Decentralized storage refers to the use of a network of nodes to store and share data in a distributed and decentralized manner. This approach has several benefits, including:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Increased security: Decentralized storage makes it more difficult for hackers or attackers to access or compromise the data, as there is no single point of failure or vulnerability.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Increased privacy: Decentralized storage allows users to control and manage their data, without having to rely on third-party service providers that may collect or share their data.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Reduced costs: Decentralized storage can be more cost-effective than traditional storage systems, as it eliminates the need for centralized servers or data centers, as well as the associated costs of managing and maintaining them.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h1&gt;
  
  
  Distributed ledger technology
&lt;/h1&gt;

&lt;p&gt;Distributed ledger technology (DLT) is a type of database that is shared across a network of nodes and updated through a consensus mechanism. DLT is a fundamental component of blockchain technology, as it allows for the secure and transparent storage and transfer of data. In blockchain storage, DLT is used to store and manage the data in a decentralized and distributed manner, ensuring its integrity and immutability.&lt;/p&gt;

&lt;h1&gt;
  
  
  IPFS (InterPlanetary File System)
&lt;/h1&gt;

&lt;p&gt;IPFS (InterPlanetary File System) is a distributed file system that provides a decentralized method of storing and accessing files on the internet. It was created to address some of the limitations of traditional centralized file storage systems, such as slow download speeds, high bandwidth costs, and the risk of data loss or censorship.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--T1aol-9q--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn.hashnode.com/res/hashnode/image/upload/v1677424348118/be35550d-9d05-46bb-9b1a-ca3ee1226a14.jpeg%3Fauto%3Dcompress%2Cformat%26format%3Dwebp" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--T1aol-9q--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn.hashnode.com/res/hashnode/image/upload/v1677424348118/be35550d-9d05-46bb-9b1a-ca3ee1226a14.jpeg%3Fauto%3Dcompress%2Cformat%26format%3Dwebp" width="800" height="245"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Whenever you search for something on the internet like a picture of a cat 🐈, the search engine would provide you with a link, &lt;code&gt;https://website.com/cat.jpg&lt;/code&gt; this means there is a computer in the world in which the picture of the cat is stored and we are accessing it using the link. This is called location-based addressing. Suppose the computer is off then the cat image is also not available. There may be some people who have already downloaded the image of the cat but we can't get it from that person.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--vDck7ifX--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn.hashnode.com/res/hashnode/image/upload/v1677425046369/5a267c53-8f06-476d-aa17-d98284970e47.jpeg%3Fauto%3Dcompress%2Cformat%26format%3Dwebp" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--vDck7ifX--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn.hashnode.com/res/hashnode/image/upload/v1677425046369/5a267c53-8f06-476d-aa17-d98284970e47.jpeg%3Fauto%3Dcompress%2Cformat%26format%3Dwebp" width="800" height="245"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Content-Base Addressing
&lt;/h2&gt;

&lt;p&gt;IPFS uses &lt;strong&gt;Content Base Addressing&lt;/strong&gt; instead of location, so what does it mean? Instead of locating the file with its address, IPFS located the file with its content. In the article &lt;a href="https://jyotirmoy.dev/cryptography"&gt;Cryptography&lt;/a&gt;, we have seen how each file has a unique hash, IPFS uses this hash method to locate files.&lt;/p&gt;

&lt;p&gt;Suppose some people are connected to an IPFS network and one person has a cat image stored in his computer and other people request a cat image in that network. The person who has the image will give it.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;Give me the picture with key nsfeH7jn89N
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Another person who has requested the cat image will ask for the image with a hash, &lt;code&gt;nsfeH7jn89N&lt;/code&gt;, after the person receives the file he or she can compare the hash and verify if somebody has tampered with the data. One of the other advantages is when many people publish the same file in the IPFS, the file is created once as other files have the same hash, which makes the network very efficient.&lt;/p&gt;

&lt;h2&gt;
  
  
  Storage of data
&lt;/h2&gt;

&lt;p&gt;IPFS stores files as an object, which contains Data and Links, Each object can store up to 256kb of data and each object can store links to other objects. A simple &lt;code&gt;Hello World&lt;/code&gt; text is less than 256kb and can store in a single IPFS object. To store data of more than 256kb the data is split into more than one IPFS object and each object store data up to 256kb, after that, the system creates an empty IPFS object which links to the other split objects.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--p2mwdT_x--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn.hashnode.com/res/hashnode/image/upload/v1677505667924/b0bc685b-6b0b-48be-99ea-2c2277f43b0e.jpeg%3Fauto%3Dcompress%2Cformat%26format%3Dwebp" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--p2mwdT_x--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn.hashnode.com/res/hashnode/image/upload/v1677505667924/b0bc685b-6b0b-48be-99ea-2c2277f43b0e.jpeg%3Fauto%3Dcompress%2Cformat%26format%3Dwebp" width="800" height="217"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Once the data is added to the IPFS it can't be changed and the data become immutable because it uses a content base address, but how do we change our data if we need to? We can use versioning.&lt;/p&gt;

&lt;h2&gt;
  
  
  Versioning
&lt;/h2&gt;

&lt;p&gt;IPFS support the versioning of file just like git. Whenever we publish a file in the network, the system makes a commit object of that file. A commit object has two things Parent and Object. The parent stores the previous commit of the file and the Object points to the current version of the file.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--qR4bnwlL--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn.hashnode.com/res/hashnode/image/upload/v1677507876939/7ff30abc-68d3-47e0-aab6-172faea95760.jpeg%3Fauto%3Dcompress%2Cformat%26format%3Dwebp" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--qR4bnwlL--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn.hashnode.com/res/hashnode/image/upload/v1677507876939/7ff30abc-68d3-47e0-aab6-172faea95760.jpeg%3Fauto%3Dcompress%2Cformat%26format%3Dwebp" width="800" height="253"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;IPFS makes sure that your file and its entire history are accessible to other nodes on the network.&lt;/p&gt;

&lt;h1&gt;
  
  
  What's on the next article?
&lt;/h1&gt;

&lt;p&gt;Next, we will what is Mining and Incentive Models.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Cryptography</title>
      <dc:creator>Jyotirmoy Barman</dc:creator>
      <pubDate>Thu, 23 Feb 2023 14:54:02 +0000</pubDate>
      <link>https://dev.to/jyotirmoydotdev/cryptography-19hp</link>
      <guid>https://dev.to/jyotirmoydotdev/cryptography-19hp</guid>
      <description>&lt;p&gt;Cryptography is a huge topic and constantly evolving as the internet get advances. Here I will explain the topics that will help you understand blockchain better. The word cryptography comes from two words the prefix &lt;code&gt;crypto&lt;/code&gt; means “hidden” and the suffix &lt;code&gt;graphy&lt;/code&gt; means “writing”. Cryptography is a field of study of secure communication and encryption, With it, we can secure our information and securely communicate with others on the internet as no third person can read it or misuse our data. When we encrypt some data, it can't be read by humans and even computers, to make it possible to use some algorithms like Secure Hash Algorithm (SHA), Message Digest (MD), Windows NTHash, RACE Integrity Primitives Evaluation Message Digest (RIPEMD), Whirlpool, and RSA. The most popular blockchain like Bitcoin and Ethereum use SHA256. But before we know what SHA256 is, we need to understand Hash Function or Hash.&lt;/p&gt;

&lt;h1&gt;
  
  
  Hash Function
&lt;/h1&gt;

&lt;p&gt;In python3 we have an inbuilt function &lt;code&gt;hash()&lt;/code&gt;, which returns the hash integer value of an object, the object can be a string, integer, float, or tuple. Each object pass in the hash function has a unique and fixed-size output but the same object has the same hash value. The hash function generally outputs a fixed-size value, remember that the hash function is a one-way function, in which we can convert an object into a hash value but it is very difficult to convert a hash value to an object. The values returned by a hash function are called hash values, hash codes, digests, or simply hashes.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="o"&gt;&amp;gt;&amp;gt;&amp;gt;&lt;/span&gt; &lt;span class="nf"&gt;hash&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Hello World!&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="mi"&gt;8733196720692250248&lt;/span&gt;
&lt;span class="o"&gt;&amp;gt;&amp;gt;&amp;gt;&lt;/span&gt; &lt;span class="nf"&gt;hash&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Hi&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;7322946855749321176&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Let us understand with an example, suppose we want to store passwords in the database, we can store passwords in plain text but it will be very risky. So we can use a hash function to store passwords. In the below table, you can see the passwords are stored as a hash value. Whenever users want to access their accounts, the password first converts into a hash value and compares with a hash value that is stored in the database.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;User ID&lt;/th&gt;
&lt;th&gt;Password&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;user1&lt;/td&gt;
&lt;td&gt;8068189639244901433&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;user2&lt;/td&gt;
&lt;td&gt;-1338079075162857857&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;user3&lt;/td&gt;
&lt;td&gt;-4837162360507738362&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;This is a simple example of a hash function but there are more Hash functions like MD5 and SHA256, in the blockchain we mostly use SHA256.&lt;/p&gt;

&lt;h1&gt;
  
  
  SHA256 Hash Function
&lt;/h1&gt;

&lt;p&gt;SHA256 stood for &lt;strong&gt;Secure Hash Algorithm 256-bit and&lt;/strong&gt; was designed by the United States National Security Agency and was first published in 2001. No matter how much the input size is the output will always be 64 characters string which is called a digest.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;Input &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"Hello World!"&lt;/span&gt;
7f83b1657ff1fc53b92dc18148a1d65dfc2d4b1fa3d677284addd200126d9069
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Python has a built-in library called &lt;code&gt;hashlib()&lt;/code&gt; which is designed to provide a common interface to different secure hashing algorithms. The module provides constructor methods for each type of hash. For example, the &lt;code&gt;.sha256()&lt;/code&gt; constructor is used to create a SHA256 hash.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;hashlib&lt;/span&gt;
&lt;span class="n"&gt;password&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;hello1234&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;
&lt;span class="n"&gt;hashed_password&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;hashlib&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;sha256&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;password&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;encode&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;utf-8&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)).&lt;/span&gt;&lt;span class="nf"&gt;hexdigest&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;hashed_password&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;hashlib&lt;/code&gt; is a module that implements a common interface to many different secure hash and message digest algorithms. Included are the FIPS secure hash algorithms SHA1, SHA224, SHA256, SHA384, and SHA512 (defined in FIPS 180-2) as well as RSA’s MD5 algorithm (defined in Internet &lt;strong&gt;RFC 1321&lt;/strong&gt;).&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;User ID&lt;/th&gt;
&lt;th&gt;Password&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;user1&lt;/td&gt;
&lt;td&gt;b9c950640e1b3740e98acb93e669c65766f6670dd1609ba91ff41052ba48c6f3&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;user2&lt;/td&gt;
&lt;td&gt;d84464181f7f019f3fb10e6bbd06f543d7ac84c4f8e360ebb9402a472ab30ebc&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;user3&lt;/td&gt;
&lt;td&gt;9e4095417158189ad876acbba90c1c61d5767c2e1a507910c4a37cd8a7271d12&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Now our passwords are stored in digests, but there is a problem every time we hash an object the same digest is output, Why it is a problem? Suppose there is a database where the most used password is stored with its digest. They can use their database to search the digest and can get the password. To solve this problem we use a nonce.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Password&lt;/th&gt;
&lt;th&gt;Digest&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;password1234&lt;/td&gt;
&lt;td&gt;b9c950640e1b3740e98acb93e669c65766f6670dd1609ba91ff41052ba48c6f3&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;1234password&lt;/td&gt;
&lt;td&gt;d84464181f7f019f3fb10e6bbd06f543d7ac84c4f8e360ebb9402a472ab30ebc&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;ThisIsPassword&lt;/td&gt;
&lt;td&gt;9e4095417158189ad876acbba90c1c61d5767c2e1a507910c4a37cd8a7271d12&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;h1&gt;
  
  
  Nonce
&lt;/h1&gt;

&lt;p&gt;In the previous article &lt;a href="https://jyotirmoy.hashnode.dev/blockchain-structure#heading-block" rel="noopener noreferrer"&gt;Blockchain Structure&lt;/a&gt;, there was a section 'Block' in which I have given a short description of Nonce, &lt;em&gt;Nonce is a random number that is used in the proof-of-work mechanism to validate the block and add it to the blockchain.&lt;/em&gt; We can implement this idea to generate a different digest of the same password or object.&lt;/p&gt;

&lt;p&gt;UUID, &lt;strong&gt;&lt;em&gt;Universal Unique Identifier&lt;/em&gt;&lt;/strong&gt;, is a python library that helps in generating random objects of 128 bits as ids. &lt;code&gt;uuid.uuid4().hex&lt;/code&gt; we can use this code to generate a random hash. Whenever we call &lt;code&gt;generate_hash(password)&lt;/code&gt; function we create a Nonce and a Digest, which we store on our database.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;uuid&lt;/span&gt;
&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;hashlib&lt;/span&gt;

&lt;span class="n"&gt;password&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;hello1234&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;

&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;generate_hash&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;password&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="n"&gt;nonce&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;uuid&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;uuid4&lt;/span&gt;&lt;span class="p"&gt;().&lt;/span&gt;&lt;span class="nb"&gt;hex&lt;/span&gt; &lt;span class="c1"&gt;# This nonce need to store in database
&lt;/span&gt;    &lt;span class="nb"&gt;hash&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;hashlib&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;sha256&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="n"&gt;password&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;encode&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;utf-8&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;&lt;span class="o"&gt;+&lt;/span&gt;&lt;span class="n"&gt;nonce&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;encode&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;utf-8&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)).&lt;/span&gt;&lt;span class="nf"&gt;hexdigest&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nb"&gt;hash&lt;/span&gt;

&lt;span class="nf"&gt;print &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;generate_hash&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;password&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;User Name&lt;/th&gt;
&lt;th&gt;Nonce&lt;/th&gt;
&lt;th&gt;Password&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;user1&lt;/td&gt;
&lt;td&gt;30eac1d2bdfe42de8cd8fc34c105f95c&lt;/td&gt;
&lt;td&gt;31bb06a1c78d0709e126686d7f5dc086d68c6b6aa10587305a4273228ada131b&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;user2&lt;/td&gt;
&lt;td&gt;12c0ba5f3bb943fd81f2e9de76b0f907&lt;/td&gt;
&lt;td&gt;01f8326285644388aa414922145aaeaf1bd9104f28193bbd32103799f6827a01&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;user3&lt;/td&gt;
&lt;td&gt;e3155754796b4cb0824e7fdbffcc471c&lt;/td&gt;
&lt;td&gt;838d518e1ffb4844ac6d8d751588cf0e43b2bde0bd015c051e026dc9e0668b1e&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;To check if the password is correct, we take the password from the user and the nonce and the stored digest from the database, recreate the digest and check if the recreated digest is the same as the stored digest.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;uuid&lt;/span&gt;
&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;hashlib&lt;/span&gt;

&lt;span class="c1"&gt;# let us get password from the user
&lt;/span&gt;&lt;span class="n"&gt;password&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;hello1234&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;

&lt;span class="c1"&gt;# let us get saved nonce and digest from the database
&lt;/span&gt;&lt;span class="n"&gt;nonce&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;e3e39410b9d3481ba3c315a77b533c59&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;
&lt;span class="n"&gt;hash_password&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;959595f7145ab845a0dceb476d980c4118467ef637a7178502400ba6ce5929ff&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;

&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;check&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;password&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="n"&gt;nonce&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="c1"&gt;# recreate the digest
&lt;/span&gt;    &lt;span class="n"&gt;user_hash&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;hashlib&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;sha256&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="n"&gt;password&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;encode&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;utf-8&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;&lt;span class="o"&gt;+&lt;/span&gt;&lt;span class="n"&gt;nonce&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;encode&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;utf-8&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)).&lt;/span&gt;&lt;span class="nf"&gt;hexdigest&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
    &lt;span class="c1"&gt;# checking the user hash with the stored hash
&lt;/span&gt;    &lt;span class="nf"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;user_hash&lt;/span&gt;&lt;span class="o"&gt;==&lt;/span&gt;&lt;span class="n"&gt;hash_password&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="bp"&gt;True&lt;/span&gt;
    &lt;span class="k"&gt;else&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="bp"&gt;False&lt;/span&gt;

&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;check&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;password&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="n"&gt;nonce&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h1&gt;
  
  
  What is Encryption
&lt;/h1&gt;

&lt;p&gt;Encryption is the process of changing plain text which is human-readable to a ciphertext that humans can't read. This is a two-way process which means when we encrypt data, we can change or decrypt it to its original form. To decrypt data we need a key, key is a random string of bits generated specifically to scramble and unscramble data.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1677002643710%2F6bb92483-c45b-419c-a40a-537bd9e61751.jpeg%3Fauto%3Dcompress%2Cformat%26format%3Dwebp" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1677002643710%2F6bb92483-c45b-419c-a40a-537bd9e61751.jpeg%3Fauto%3Dcompress%2Cformat%26format%3Dwebp"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  Symmetric Key Encryption
&lt;/h1&gt;

&lt;p&gt;With symmetric-key encryption, the same key is used to encrypt and decrypt the data. The simplest and least secure method of encryption is this one. A secure method of key transfer is required since the recipient needs the key to decrypt the message. The middle data can be read by anyone possessing the key.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1677002266686%2F28efb650-495d-49a0-819b-118694fb06a8.jpeg%3Fauto%3Dcompress%2Cformat%26format%3Dwebp" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1677002266686%2F28efb650-495d-49a0-819b-118694fb06a8.jpeg%3Fauto%3Dcompress%2Cformat%26format%3Dwebp"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Python has a library &lt;code&gt;cryptography&lt;/code&gt; which will help us to encrypt our data. cryptography includes both high-level recipes and low-level interfaces to common cryptographic algorithms such as symmetric ciphers, message digests, and key derivation functions. Install &lt;code&gt;cryptography&lt;/code&gt; with:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;pip &lt;span class="nb"&gt;install &lt;/span&gt;cryptography
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To perform encryption and decryption of a message using the Fernet symmetric encryption algorithm. Here's the step-by-step process:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Import the &lt;code&gt;Fernet&lt;/code&gt; class from the &lt;code&gt;cryptography.fernet&lt;/code&gt; module.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Define a message string, which is "I need coffee" in this case.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Generate a random encryption key using the &lt;code&gt;generate_key()&lt;/code&gt; method of the &lt;code&gt;Fernet&lt;/code&gt; class.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Print the key to the console. This key will be used to both encrypt and decrypt the message.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Create an &lt;code&gt;Fernet&lt;/code&gt; object using the key generated in step 3.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Use the &lt;code&gt;encrypt()&lt;/code&gt; method of the &lt;code&gt;Fernet&lt;/code&gt; object to encrypt the message. The &lt;code&gt;encode()&lt;/code&gt; method is used to convert the message string to bytes, which is required for encryption.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Print the original message and the encrypted message to the console.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Use the &lt;code&gt;decrypt()&lt;/code&gt; method of the &lt;code&gt;Fernet&lt;/code&gt; objects to decrypt the encrypted message. The &lt;code&gt;decode()&lt;/code&gt; method is used to convert the decrypted bytes to a string.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Print the decrypted message to the console.&lt;br&gt;
&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;cryptography.fernet&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;Fernet&lt;/span&gt;

&lt;span class="n"&gt;message&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;I need coffee&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;

&lt;span class="n"&gt;key&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;Fernet&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;generate_key&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;key&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="n"&gt;fernet&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;Fernet&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;key&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="n"&gt;encMessage&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;fernet&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;encrypt&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;message&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;encode&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt;

&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;original string: &lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;message&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;encrypted string: &lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;encMessage&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="n"&gt;decMessage&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;fernet&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;decrypt&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;encMessage&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;decode&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;

&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;decrypted string: &lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;decMessage&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Note that because the encryption key is randomly generated each time the code is run, the encrypted message will be different each time.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Output

original string: I need coffee
encrypted string:  b'gAAAAABj9OSJfh9U2eiGTnogdjOVbCKhhceTXYkwYlDLkR_V2JouTw1hBDTgRPpKa3hGkxR4Im3GS1r0YSDhqetouD94i69lLA=='
decrypted string:  I need coffee
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h1&gt;
  
  
  Public Key Cryptography
&lt;/h1&gt;

&lt;p&gt;Public key cryptography, also known as asymmetric cryptography, is a cryptographic system that uses two mathematically related keys – a public key and a private key – to encrypt and decrypt messages. The keys are generated in such a way that the public key can be widely distributed and shared with anyone, while the private key is kept secret and only known to the owner.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1677005455952%2F1b7d433d-33d4-4b05-a51a-36f11272986d.jpeg%3Fauto%3Dcompress%2Cformat%26format%3Dwebp" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1677005455952%2F1b7d433d-33d4-4b05-a51a-36f11272986d.jpeg%3Fauto%3Dcompress%2Cformat%26format%3Dwebp"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The public key is used to encrypt messages, which can then only be decrypted with the corresponding private key. This means that anyone can encrypt a message using the recipient's public key, but only the recipient with the corresponding private key can decrypt the message. In this way, public key cryptography enables secure communication between two parties who have never met or shared a secret key before.&lt;/p&gt;

&lt;h1&gt;
  
  
  Secure Communication
&lt;/h1&gt;

&lt;p&gt;To understand public key cryptography we need to see how we can use this concept to message someone securely in a network. Let us consider we have 4 people in the network &lt;em&gt;Green, Blue, Purple,&lt;/em&gt; and &lt;em&gt;Red&lt;/em&gt;. Here &lt;em&gt;Green&lt;/em&gt; wants to send a message to &lt;em&gt;Blue,&lt;/em&gt; so what he should do?&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Every person in the network needs to generate their own &lt;strong&gt;Public Key&lt;/strong&gt; 🗝️ and a &lt;strong&gt;Private key 🔑&lt;/strong&gt;. The Private Key needs to keep secret 🤫.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Now, every person in the network can broadcast their public key in the network.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;em&gt;Green&lt;/em&gt; can take &lt;em&gt;Bule’s&lt;/em&gt; public key 🗝️ from the network and encrypt the message with it, which will give us a cipher text.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Now, &lt;em&gt;Green&lt;/em&gt; can broadcast this cipher text to the network, where every person in the network can access this encrypted text.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;But since the corresponding private key 🔑 is only known to Blue, only Blue can decrypt it. Any other person in the network can't decrypt it.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1677090121557%2F305ca505-d05a-436a-83a3-4e5be8cb739a.gif%3Fauto%3Dformat%2Ccompress%26gif-q%3D60%26format%3Dwebm" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1677090121557%2F305ca505-d05a-436a-83a3-4e5be8cb739a.gif%3Fauto%3Dformat%2Ccompress%26gif-q%3D60%26format%3Dwebm"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;When Blue receives a message, which when he decrypts says “I Need Coffee”. How can Blue know that Green and not others sent the message?&lt;/p&gt;

&lt;h1&gt;
  
  
  Digital Signatures
&lt;/h1&gt;

&lt;p&gt;Blue gets the cipher text and he decrepit it with his private key but Blue does not know who sends this message in the network. He knows it was sent for him as he was able to decrepit the message.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1677091825523%2Fa5186633-17fb-4733-a52b-70280f884ac0.jpeg%3Fauto%3Dcompress%2Cformat%26format%3Dwebp" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1677091825523%2Fa5186633-17fb-4733-a52b-70280f884ac0.jpeg%3Fauto%3Dcompress%2Cformat%26format%3Dwebp"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;A &lt;strong&gt;digital signature&lt;/strong&gt; is a mathematical scheme for verifying the authenticity of digital messages or documents. A valid digital signature, where the prerequisites are satisfied, gives a recipient very high confidence that the message was created by a known sender (authenticity), and that the message was not altered in transit (integrity).&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;This can be achieved if the message is “signed” by its sender (&lt;em&gt;Green&lt;/em&gt;). The receiver of the message can then verify the signatures.&lt;/p&gt;

&lt;p&gt;The first method we can use is to encrypt the message with Green's Private Key 🔑 so that when Blue receives the cipher text, he can decrypt it with Green's Public Key🗝️. With this, he surely knows that Green send this message to the network.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1677091561039%2Fbb0e3b0f-34a7-4bdc-8a4f-d25acdfcc94a.gif%3Fauto%3Dformat%2Ccompress%26gif-q%3D60%26format%3Dwebm" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1677091561039%2Fbb0e3b0f-34a7-4bdc-8a4f-d25acdfcc94a.gif%3Fauto%3Dformat%2Ccompress%26gif-q%3D60%26format%3Dwebm"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;But there is a problem when Green broadcast this message to the network everybody can decrypt this message as Green's public key is already available in the network.&lt;/p&gt;

&lt;p&gt;Instead of signing the entire lengthy message the sender computes a hash (digest) of the message and signs that with his public key instead. The receiver can then re-compute the message hash and compare it with the signed hash to ensure that message was not tampered with.&lt;/p&gt;

&lt;h2&gt;
  
  
  Adding a Digital Signature
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;em&gt;Green&lt;/em&gt; computes a message digest by hashing the message she is about to send. SHA256(“I Need Coffee”).&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;em&gt;Green&lt;/em&gt; calculates the message digest = HASH(message);&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;em&gt;Green&lt;/em&gt; signs the message digest by encrypting it with her private key.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;em&gt;Green&lt;/em&gt; appends the signed digest with a message and encrypts it with &lt;em&gt;Blue's&lt;/em&gt; public key &lt;em&gt;Green&lt;/em&gt; sends it over to &lt;em&gt;Blue.&lt;/em&gt;&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1677097365003%2Fa8b0f78b-58a6-43b6-9fc3-cc2a6a398b8e.jpeg%3Fauto%3Dcompress%2Cformat%26format%3Dwebp" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1677097365003%2Fa8b0f78b-58a6-43b6-9fc3-cc2a6a398b8e.jpeg%3Fauto%3Dcompress%2Cformat%26format%3Dwebp"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Verifying a Digital Signature
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;em&gt;Blue&lt;/em&gt; decrypts the message using his private key&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;em&gt;Blue&lt;/em&gt; decrypts the digest using &lt;em&gt;Green's&lt;/em&gt; public key&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;em&gt;Blue&lt;/em&gt; computes the digest of the message. If it matches the digest he received as signatures it confirms that:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The message is not tampered with&lt;/li&gt;
&lt;li&gt;The message has been sent by &lt;em&gt;Green&lt;/em&gt; only - Since only &lt;em&gt;Green's&lt;/em&gt; public key could decrypt the hash&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1677098376952%2F61f00381-2e7a-45a0-99a7-d661cb429868.jpeg%3Fauto%3Dcompress%2Cformat%26format%3Dwebp" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1677098376952%2F61f00381-2e7a-45a0-99a7-d661cb429868.jpeg%3Fauto%3Dcompress%2Cformat%26format%3Dwebp"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;But wait! how could &lt;em&gt;Blue&lt;/em&gt; know the public key🗝️ which he is using truly belong to &lt;em&gt;Green&lt;/em&gt;? it could be &lt;em&gt;Red&lt;/em&gt; pretending to be &lt;em&gt;Green&lt;/em&gt;.&lt;/p&gt;

&lt;h1&gt;
  
  
  Certificate Authority
&lt;/h1&gt;

&lt;p&gt;In a network, there can be people who can pretend to be someone or we can say, fake people. To deal with this type of problem, we set up a &lt;strong&gt;Certificate Authority&lt;/strong&gt;. Think of it as an Authority that is responsible for verifying our public key in the network.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1677130753249%2F5af1069c-eda0-49e0-8e22-bb0fc01e6c1b.jpeg%3Fauto%3Dcompress%2Cformat%26format%3Dwebp" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1677130753249%2F5af1069c-eda0-49e0-8e22-bb0fc01e6c1b.jpeg%3Fauto%3Dcompress%2Cformat%26format%3Dwebp"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  How does a Certificate Authority work?
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;em&gt;Green&lt;/em&gt; must contact the CA to get a certificate(digitally signed public key) to prove her public key to others. All other participants on the network will be able to trust the public key is &lt;em&gt;Green's&lt;/em&gt; if they trust the CA.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The CA would take &lt;em&gt;Green&lt;/em&gt; through an approval/onboarding/manual verification process and issue a certificate. The certificate itself is a list of certified attributes of the entity it issued to &lt;em&gt;Green&lt;/em&gt;. It has attributes like the public key, the name of the holder, etc. All this data is digitally signed by the CA using its private key.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;em&gt;Green&lt;/em&gt; then shares this certificate as proof of his public key with &lt;em&gt;Blue&lt;/em&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Since &lt;em&gt;Blue&lt;/em&gt; has the CA in his trusted CA list(CA’s public key), he can verify and trust the certificate shared by &lt;em&gt;Green&lt;/em&gt; and hence trust her public key.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1677133867358%2Fb8528a4e-59c0-43ff-96f9-196402e5a00b.jpeg%3Fauto%3Dcompress%2Cformat%26format%3Dwebp" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1677133867358%2Fb8528a4e-59c0-43ff-96f9-196402e5a00b.jpeg%3Fauto%3Dcompress%2Cformat%26format%3Dwebp"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1677138121370%2Fd5ad18a8-2965-470e-b146-ae902831f9d4.jpeg%3Fauto%3Dcompress%2Cformat%26format%3Dwebp" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1677138121370%2Fd5ad18a8-2965-470e-b146-ae902831f9d4.jpeg%3Fauto%3Dcompress%2Cformat%26format%3Dwebp"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  What's on the next article?
&lt;/h1&gt;

&lt;p&gt;Next, we will see how blockchain storage work.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Decentralization with Blockchain</title>
      <dc:creator>Jyotirmoy Barman</dc:creator>
      <pubDate>Sat, 18 Feb 2023 07:51:16 +0000</pubDate>
      <link>https://dev.to/jyotirmoydotdev/decentralization-with-blockchain-mhl</link>
      <guid>https://dev.to/jyotirmoydotdev/decentralization-with-blockchain-mhl</guid>
      <description>&lt;p&gt;To understand decentralization first we need to understand our current internet or web2, in our current internet model, a few companies are controlling the internet like Amazon, Google, Microsoft, etc.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;The Internet is an interconnected network of computers around the world.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h1&gt;
  
  
  How does the internet works?
&lt;/h1&gt;

&lt;p&gt;You are reading this article on your device, but did you know how you get it? you probably think you just type the article name on Google or type the URL of this page on your web browser and the page appears but there is more to know.&lt;/p&gt;

&lt;p&gt;If we want to communicate between computer we need to link them, we can be connected them by wire but when there are many computers then the wiring becomes complex, Suppose we want to communicate between 10 computer each computer need to connect to the other 9 computers with wire and we need to do the same with rest other 9 computers, so we need total 45 wire just to connect 10 computer directly to each other.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fum1te4i26pj0m9s2qck4.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fum1te4i26pj0m9s2qck4.png" alt=" " width="800" height="304"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;To make this simplify we can use a router, routers are the devices that manage and make sure the message route to the correct device. We can connect the router with only a few computers but as the router is also a computer it can connect to another router to form a network. Suppose a router can connect to 10 devices and there are 3 routers each connecting to 5 computers. Still, if we want to send a message from router 1 computer to router 2 computers we need to connect this router so we can use another router to secure it.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fnd5gjhkywompkkqe5zi2.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fnd5gjhkywompkkqe5zi2.png" alt=" " width="800" height="304"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The network we just created is contained to our self like in a building or a local area but if we want to connect to other networks around the world we need a well-structured infrastructure that is connected to other networks, so here comes the play of ISP( internet service provider ) like JIO, Airtel, and BSNL they are the internet provider or like a router which connected around the world. This forms a network of computers which we called the Internet.&lt;/p&gt;

&lt;p&gt;Now the question here is, How this article is displayed on your device, and where from this data come from? Every computer has a unique IP address, the IP address is a unique string of characters that identifies each computer using the Internet Protocol to communicate over a network. Whenever we upload some data to the internet like Photos, Videos, or Articles this is stored in a Data-Center, Data-Centres are massive computers with lots of data storage that store the data. This article is stored in a Data-Center, suppose we can say this article is stored in a Data-Center which is located in Mumbai, and that Data-Center is connected to an internet service provider, So when we call the server with this article's URL on our browser, the browser will look into DNS and return the IP address. After we obtain the address we form a connection and access this article.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;&lt;em&gt;The Domain Name System&lt;/em&gt;&lt;/strong&gt; (DNS) is the phonebook of the Internet where every URL is mapped to the IP address of the server.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F35rpcrm5vf5wv8xbrp76.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F35rpcrm5vf5wv8xbrp76.png" alt=" " width="800" height="123"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  How the internet is centralized?
&lt;/h1&gt;

&lt;p&gt;The internet can be decentralized but there is some aspect of the internet that is centralized and can be problematic. Here are some of the centralized points:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Control of infrastructure&lt;/strong&gt;: As we have seen the internet is made of many computers around the world and that can be decentralized but to make this structure we need ISPs and hosting providers, and this means the company which provides it has the power to control the internet. Here is an example, if the government wants to block some websites in their country, they order the ISPs to block the URL of the website.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;The dominance of a few large companies:&lt;/strong&gt; There are some segments of the internet which is control over by a few big companies, such as Google holds a &lt;em&gt;92.9%&lt;/em&gt; share of the search engine segment, and Meta holds &lt;em&gt;76.55%&lt;/em&gt; of the social media segment. This affects the free flow of information, privacy, and competition.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Use of centralized platforms and services:&lt;/strong&gt; when we want to surf the internet we need an email address like Gmail or when we need to message someone we need to use a messaging app like WhatsApp and if we want to store data in the cloud we need a cloud storage company like Google cloud or iCloud, this service is often centralized and we need to depend on this companies to handle our data correctly and if there is any data leak or misuse of our data it can affect or privacy.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h1&gt;
  
  
  What is Decentralization?
&lt;/h1&gt;

&lt;p&gt;Decentralization refers to the concept of distributing the power from a single decision-making authority to individuals or entities. Instead of relying on a single group of people to make all the decisions the power is distributed among many parties. The concept of decentralization can be implemented in many places like ownership, finance, land record, politics, and many more.&lt;/p&gt;

&lt;p&gt;Blockchain helps us to implement this concept in the real world. Decentralization is the key characteristic of blockchain technology. All participants have equal access to the network and can participate in the decision-making process.&lt;/p&gt;

&lt;p&gt;In a blockchain network, transactions are verified and added to the blockchain through a process known as consensus. Consensus is achieved through a decentralized network of nodes that work together to validate transactions and maintain the integrity of the blockchain. Each node has a copy of the blockchain and uses algorithms to verify transactions and reach consensus with other nodes.&lt;/p&gt;

&lt;h1&gt;
  
  
  Why it matters?
&lt;/h1&gt;

&lt;p&gt;In our current internet, some companies are responsible for the critical functioning of the internet but as these companies are centralized systems, if the centralized authority is compromised, the entire system may be at risk. Decentralization can provide greater &lt;strong&gt;security&lt;/strong&gt; by reducing the risk of a single point of failure. As blockchain has distributed control among multiple nodes, it is difficult to compromise the entire system.&lt;/p&gt;

&lt;p&gt;One of the other points is that there is minimal to no transparency in the centralized system, the decision-making and transaction are decided only by a few people and it is difficult for an outsider to know what happens in a company. But, in a blockchain, everyone can contribute to and verify every transaction, this established a great &lt;strong&gt;transparent&lt;/strong&gt; and &lt;strong&gt;open system&lt;/strong&gt; that helps build trust.&lt;/p&gt;

&lt;p&gt;As I have explained before that in blockchain the control is distributed among multiple nodes, which means anyone can run a node and have equal control as others, and everyone has equal access to services and opportunities on the blockchain. This provides greater &lt;strong&gt;access&lt;/strong&gt; by removing intermediaries and enabling peer-to-peer transactions.&lt;/p&gt;

&lt;h1&gt;
  
  
  Applications and uses
&lt;/h1&gt;

&lt;p&gt;There can be many applications of blockchain but some of the famous uses of blockchain are :&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Decentralized finance (DeFi) 💸:&lt;/strong&gt; The money you own is controlled by the government and centralized authorities, who can block payments or deny you access to your money. There is also the risk of error and corruption due to human intervention in our current financial system. As an alternative, we can use Decentralized finance (DeFi), a collective term for financial products and services that are accessible to anyone which is based on blockchain. Here every transaction is open and accessible to anyone with an internet connection.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Non-fungible tokens (NFT) 🖼️:&lt;/strong&gt; NFT provides proof of ownership of digital assets on the internet. Suppose you create a digital asset like a collectable, music, or video, How do you prove it is yours? Whenever you minted a digital asset on a blockchain it creates a unique token of that NFT and stores it in your wallet, it now lives on the blockchain and anybody can verify that it is yours. As you have minted it first. NFTs can also use to prove the ownership of real-world objects or assets.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Decentralized autonomous organizations (DAOs) 🤝:&lt;/strong&gt; DAOs are the digit organization that lives on the blockchain, in this organization there is no central authority, and rules are written on smart contracts. The voting system of a DAO is typically based on the amount of cryptocurrency that a member has invested in the organization, known as tokens or shares.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;There are more applications and uses of blockchain which I will explain in detail later in this series.&lt;/p&gt;

&lt;h1&gt;
  
  
  What's on the next article?
&lt;/h1&gt;

&lt;p&gt;Next, we will see what is cryptography as it is important to know before we start learning blockchain.&lt;/p&gt;

</description>
      <category>react</category>
      <category>discuss</category>
      <category>webdev</category>
    </item>
    <item>
      <title>Blockchain Structure</title>
      <dc:creator>Jyotirmoy Barman</dc:creator>
      <pubDate>Sun, 12 Feb 2023 10:02:35 +0000</pubDate>
      <link>https://dev.to/jyotirmoydotdev/blockchain-structure-1g0k</link>
      <guid>https://dev.to/jyotirmoydotdev/blockchain-structure-1g0k</guid>
      <description>&lt;p&gt;Today we are going to see how a blockchain work. In our previous article, we have seen some of the terminologies related to it, if you have not read it you should go through it "&lt;a href="https://jyotirmoy.hashnode.dev/what-is-blockchain" rel="noopener noreferrer"&gt;What is Blockchain?&lt;/a&gt;".&lt;/p&gt;

&lt;p&gt;This article will be divided into 6 parts :&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;SHA256 Hash&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Block&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Blockchain&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Distributed Blockchain&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Tokens or Transaction&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h1&gt;
  
  
  SHA256 Hash
&lt;/h1&gt;

&lt;p&gt;First, let us see what is &lt;strong&gt;SHA256 HASH&lt;/strong&gt; I will explain it in detail later on. Here is a short description, SHA256 Hash is a function that takes an input and returns a fixed 256-character of string which is called Hash, and each Hash is unique for different data.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fk61jbdxikako19drk3f7.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fk61jbdxikako19drk3f7.png" alt="Image description" width="800" height="231"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F0flwuu4exj7zsfw9uhra.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F0flwuu4exj7zsfw9uhra.png" alt="Image description" width="800" height="231"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Here you can see both the hash are different as the first letter 'H' is capitalized in the first input and the 'h' small letter in the second although the other characters are the same.&lt;/p&gt;

&lt;p&gt;Later in this series, there will be an article on &lt;strong&gt;Cryptography&lt;/strong&gt; here I will explain this topic thoroughly.&lt;/p&gt;

&lt;h1&gt;
  
  
  Block
&lt;/h1&gt;

&lt;p&gt;Now we will see what is a block, In simple in a block we have a block number, nonce, data, and hash. Here you can see the new word &lt;strong&gt;&lt;em&gt;Nonce&lt;/em&gt;,&lt;/strong&gt; now you are thinking what is a nonce? &lt;em&gt;Nonce is a random number that is used in the proof-of-work mechanism to validate the block and add it to the blockchain.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fmm9mselwddcokqsq2knq.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fmm9mselwddcokqsq2knq.png" alt="Image description" width="800" height="333"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;To generate a signed hash that can be added to a blockchain, the input data, such as "Hello World!", must first be hashed using a cryptographic hash function. The resulting unsigned hash, such as "7f83b......d9069", is not suitable for this purpose as it does not meet the specific criteria required for a block hash in a blockchain.&lt;/p&gt;

&lt;p&gt;To produce a signed hash, a miner employs a brute-force approach to find a nonce value that, when combined with the block number and data, generates a hash that meets the necessary criteria. This often involves starting with a nonce of 1 and incrementing it until a value is found that produces a hash that begins with the desired number of zeros (e.g. "0000"). The combination of the block number, nonce, and data results in the final block hash, which can then be added to the blockchain.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fbjtsqugiy59toi5ixn30.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fbjtsqugiy59toi5ixn30.gif" alt="Image description" width="1200" height="501"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  Blockchain
&lt;/h1&gt;

&lt;p&gt;Till now we have seen what is a block and what is a SHA256 Hash now we will see what is blockchain but before that, have you seen one more section above the &lt;code&gt;Hash&lt;/code&gt; in the below table?&lt;/p&gt;

&lt;p&gt;Blockchain is a series of blocks that contain data and which is connected to the previous block with a cryptographic hash. In a block, we have a previous hash data field that stores the hash of the previous block.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Previous Hash&lt;/strong&gt; stores the hash of the previous block so we can verify the previous block, It forms a chain-like structure as each block is connected to the previous block. In the first article, I talk about the &lt;strong&gt;Genius block&lt;/strong&gt; under the Ledger section, here you can see the first block (which is block number 1) has &lt;code&gt;Prev&lt;/code&gt; equal to "0000....000" as the first block does not have a block before it, so the previous hash will be NULL or "000....000".&lt;/p&gt;

&lt;p&gt;Whenever a new block is added to a blockchain it takes the hash of the previous block and stores it, Check block 1 &lt;code&gt;Hash&lt;/code&gt; and block 2 &lt;code&gt;Prev&lt;/code&gt;, the hash you will find is the same.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fhj3ws8z0zgg8d7tc10pu.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fhj3ws8z0zgg8d7tc10pu.png" alt="Image description" width="800" height="284"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fzzi9t7i9kqj4kbnnvaj0.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fzzi9t7i9kqj4kbnnvaj0.png" alt="Image description" width="800" height="284"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Whenever we try to temper the data of the previous block the blocks will be not valid. So, we need to mine the blocks one by one.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ff7fgo8p6omk9g2lz8jpg.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ff7fgo8p6omk9g2lz8jpg.gif" alt="Image description" width="1200" height="427"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  &lt;strong&gt;Distributed Blockchain&lt;/strong&gt;
&lt;/h1&gt;

&lt;p&gt;Now further extending the knowledge of blockchain, we will see what is Distributed blockchain. It is a system, where a ledger is replicated and distributed to each node around the world.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Blockchain &lt;strong&gt;nodes&lt;/strong&gt; are the moderators that build the infrastructure of a decentralized network.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fjnn1mocqryfyh2gtzcks.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fjnn1mocqryfyh2gtzcks.jpg" alt="Image description" width="800" height="300"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F2yzz9wivh7b96icqdxx2.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F2yzz9wivh7b96icqdxx2.jpg" alt="Image description" width="800" height="300"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fmuu96c5tkertyictqhdm.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fmuu96c5tkertyictqhdm.jpg" alt="Image description" width="800" height="300"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;A decentralized ledger that is maintained by a network of computers is known as a distributed blockchain. There is no centralized authority or single point of control in a distributed blockchain. Instead, each node in the network keeps a copy of the ledger and uses consensus techniques to verify transactions. As it becomes more challenging for any one node or set of nodes to influence the ledger, this design enables enhanced security, transparency, and reliability.&lt;/p&gt;

&lt;h1&gt;
  
  
  Tokens or Transaction
&lt;/h1&gt;

&lt;p&gt;Whenever we add a block there is some data but before the data doesn't mean anything or it was useless, to make the blockchain valuable or worth something we can store transactions.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F93ce71dnsck460xaags1.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F93ce71dnsck460xaags1.png" alt="Image description" width="800" height="574"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  Coinbase Transactions
&lt;/h1&gt;

&lt;p&gt;In the blockchain, whenever a new block is mined by the miner he is rewarded with a coin in his account, this coinbase transaction doesn't have a previous reference.&lt;/p&gt;

&lt;p&gt;Let us think the Genius block is mined by Anders so he is rewarded with 100 coins in his account now he can give these coins to other accounts in the blockchain, these coins do not have a previous reference but when Sophia tries to send coins to another account she needs to have coins in her account she can get this coin from Anders or when the blockchain was created the creates can distribute this coin.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F91tj1bpma5crm1uq7ed1.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F91tj1bpma5crm1uq7ed1.png" alt="Image description" width="800" height="595"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  What's on the next article?
&lt;/h1&gt;

&lt;p&gt;Next, we will see what is decentralization and compare it with our current internet.&lt;/p&gt;

</description>
      <category>discuss</category>
      <category>ai</category>
      <category>nlp</category>
    </item>
    <item>
      <title>What is Blockchain?</title>
      <dc:creator>Jyotirmoy Barman</dc:creator>
      <pubDate>Fri, 10 Feb 2023 19:23:18 +0000</pubDate>
      <link>https://dev.to/jyotirmoydotdev/what-is-blockchain-1e4i</link>
      <guid>https://dev.to/jyotirmoydotdev/what-is-blockchain-1e4i</guid>
      <description>&lt;p&gt;According to Wikipedia “&lt;strong&gt;A blockchain is a distributed ledger with growing lists of records (&lt;em&gt;blocks&lt;/em&gt;) that are securely linked together via cryptographic hashes.&lt;/strong&gt;” In other words, it is a list of transactions and each bundle of transactions are linked to the previous block.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F47xmhfjfc9x6z4ad63mp.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F47xmhfjfc9x6z4ad63mp.jpg" alt="Blockchain" width="800" height="304"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Blockchain is DLT (Distributed Ledger Technology) which is immutable and distributed in nature, it stores and replicated the data in each node. To understand the Blockchain we should first understand some words.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Immutability&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Distribution&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Ledger&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Node&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Terminology
&lt;/h2&gt;

&lt;p&gt;Let us see this word and what it means.&lt;/p&gt;

&lt;h3&gt;
  
  
  Immutability
&lt;/h3&gt;

&lt;p&gt;Immutability means once you have written on a blockchain it can't be deleted how much you try. It is impossible to erase data from a blockchain. So, it is considered the safest data storage. In a web2 database system, we have access to the data, we can create, modify or delete the data but in blockchain, we can only add and modify data. In web2, we need to trust the authorities and hope they don't delete or modify our data without our permission, but in blockchain, we don't need to trust others to handle our data, as no third person is involved.&lt;/p&gt;

&lt;h3&gt;
  
  
  Distribution
&lt;/h3&gt;

&lt;p&gt;In Blockchain the data Is replicated and distributed to every node or host or peer, we can trust the data if most of the node is working correctly or in a valid state if a node is misbehaving the node goes to an invalid state and the node is kicked out from the network. Each node has the whole ledger or blockchain in its local storage this guarantees high availability and security as the data is easily verifiable and accessible.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fx1u937r2df67cyfu2kec.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fx1u937r2df67cyfu2kec.jpg" alt="Distribution" width="800" height="285"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Ledger
&lt;/h3&gt;

&lt;p&gt;Ledger is a list of transactions recorded with a time stamp and stored in a block and each block is connected to the previous block, the first block or the head block does not have a previous block so its previous block is &lt;strong&gt;NULL.&lt;/strong&gt; The first block is called &lt;strong&gt;Genesis Block&lt;/strong&gt;, You can check the first block of any blockchain in &lt;a href="https://etherscan.io" rel="noopener noreferrer"&gt;etherscan.io&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fmljpcf4oh4jylz6t72hr.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fmljpcf4oh4jylz6t72hr.jpg" alt="Ledger" width="800" height="195"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Node ( Host or Peer)
&lt;/h3&gt;

&lt;p&gt;Node is the host, server, or computer in which the blockchain program runs. Think of it as a virtual machine that runs on another OS but it allocates its own resource. Each node has a copy of the blockchain in the host. Anyone can run a node if he or she has the required configuration device. By running a node anyone can earn blockchain cryptocurrencies which can be used as money in that ecosystem.&lt;/p&gt;

&lt;h2&gt;
  
  
  What's on the next article?
&lt;/h2&gt;

&lt;p&gt;In the next article, we will see the blockchain structure and how it works, so make sure to subscribe to the newsletter and follow me on Twitter.&lt;/p&gt;

</description>
      <category>watercooler</category>
    </item>
    <item>
      <title>9. Palindrome Number</title>
      <dc:creator>Jyotirmoy Barman</dc:creator>
      <pubDate>Fri, 10 Feb 2023 19:15:39 +0000</pubDate>
      <link>https://dev.to/jyotirmoydotdev/9-palindrome-number-3epb</link>
      <guid>https://dev.to/jyotirmoydotdev/9-palindrome-number-3epb</guid>
      <description>&lt;h1&gt;
  
  
  Question
&lt;/h1&gt;

&lt;p&gt;Read the Question here &lt;a href="https://leetcode.com/problems/palindrome-number/" rel="noopener noreferrer"&gt;Click Here&lt;/a&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;Input: x &lt;span class="o"&gt;=&lt;/span&gt; 121
Output: &lt;span class="nb"&gt;true
&lt;/span&gt;Explanation: 121 reads as 121 from left to right and from right to left.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h1&gt;
  
  
  Answer
&lt;/h1&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight cpp"&gt;&lt;code&gt;&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Solution&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
&lt;span class="nl"&gt;public:&lt;/span&gt;
    &lt;span class="kt"&gt;bool&lt;/span&gt; &lt;span class="n"&gt;isPalindrome&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;x&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;oldNum&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;x&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;newNum&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="k"&gt;while&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;x&lt;/span&gt;&lt;span class="p"&gt;){&lt;/span&gt;
            &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;temp&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;x&lt;/span&gt;&lt;span class="o"&gt;%&lt;/span&gt;&lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
            &lt;span class="n"&gt;newNum&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;newNum&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="o"&gt;+&lt;/span&gt;&lt;span class="n"&gt;temp&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
            &lt;span class="n"&gt;x&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;x&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;
        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;oldNum&lt;/span&gt;&lt;span class="o"&gt;==&lt;/span&gt;&lt;span class="n"&gt;newNum&lt;/span&gt;&lt;span class="p"&gt;){&lt;/span&gt;
            &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nb"&gt;true&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;
        &lt;span class="k"&gt;else&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nb"&gt;false&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt; 
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here we will reverse the number and check that the given number is equal to the new number. First, we need to store the old number in a variable as the variable &lt;code&gt;x&lt;/code&gt; will be 0 at last, so we are using &lt;code&gt;oldNum&lt;/code&gt; it as a variable to remember our given number. The variable &lt;code&gt;newNum&lt;/code&gt; is where our reverse number will be stored.&lt;/p&gt;

&lt;p&gt;Now we will use a &lt;code&gt;while&lt;/code&gt; loop and check if the x is greater than 0 and run it till the x become 0. The variable &lt;code&gt;temp&lt;/code&gt; store the last number of the x, eg., given the number 121 then 121%10=1, 1 is stored in the &lt;code&gt;temp&lt;/code&gt; . After we get the temp then we move to the next line, here we are multiplying the &lt;code&gt;newNum&lt;/code&gt; with 10 and adding the last number which we stored in temp eg., &lt;code&gt;newNum&lt;/code&gt; = 0*10+1 -&amp;gt; &lt;code&gt;newNum&lt;/code&gt; = 1 and then we will remove the last number from the &lt;code&gt;x&lt;/code&gt; by dividing &lt;code&gt;x&lt;/code&gt; by 10. This loop continues till the x become 0.&lt;/p&gt;

&lt;p&gt;Till this point new will get our reverse number which is stored in, now we just need to compare this with the &lt;code&gt;oldNum&lt;/code&gt;, if the number is the same then return true or else false.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;Input : 121

x &lt;span class="o"&gt;=&lt;/span&gt; 121
oldNum &lt;span class="o"&gt;=&lt;/span&gt; 121
newNum &lt;span class="o"&gt;=&lt;/span&gt; 0
Check &lt;span class="k"&gt;if &lt;/span&gt;x is greater than 0 &lt;span class="o"&gt;(&lt;/span&gt;0&amp;lt;121&lt;span class="o"&gt;)&lt;/span&gt; ✅
    temp &lt;span class="o"&gt;=&lt;/span&gt; x % 10 &lt;span class="o"&gt;=&lt;/span&gt; 1 
    newNum &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;newNum &lt;span class="k"&gt;*&lt;/span&gt; 10&lt;span class="o"&gt;)&lt;/span&gt; + temp &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;0&lt;span class="k"&gt;*&lt;/span&gt;10&lt;span class="o"&gt;)&lt;/span&gt; + 1 &lt;span class="o"&gt;=&lt;/span&gt; 0 + 1 &lt;span class="o"&gt;=&lt;/span&gt; 1
    x &lt;span class="o"&gt;=&lt;/span&gt; x / 10 &lt;span class="o"&gt;=&lt;/span&gt; 121 / 10 &lt;span class="o"&gt;=&lt;/span&gt; 12

x &lt;span class="o"&gt;=&lt;/span&gt; 12
oldNum &lt;span class="o"&gt;=&lt;/span&gt; 121
newNum &lt;span class="o"&gt;=&lt;/span&gt; 1
Check &lt;span class="k"&gt;if &lt;/span&gt;x is greater than 0 &lt;span class="o"&gt;(&lt;/span&gt;0&amp;lt;12&lt;span class="o"&gt;)&lt;/span&gt; ✅
    temp &lt;span class="o"&gt;=&lt;/span&gt; x % 10 &lt;span class="o"&gt;=&lt;/span&gt; 12 % 10 &lt;span class="o"&gt;=&lt;/span&gt; 2
    newNum &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;newNum &lt;span class="k"&gt;*&lt;/span&gt; 10&lt;span class="o"&gt;)&lt;/span&gt; + temp &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;1&lt;span class="k"&gt;*&lt;/span&gt;10&lt;span class="o"&gt;)&lt;/span&gt; + 2 &lt;span class="o"&gt;=&lt;/span&gt; 10 + 2 &lt;span class="o"&gt;=&lt;/span&gt; 12
     x &lt;span class="o"&gt;=&lt;/span&gt; x / 10 &lt;span class="o"&gt;=&lt;/span&gt; 12 / 10 &lt;span class="o"&gt;=&lt;/span&gt; 1

x &lt;span class="o"&gt;=&lt;/span&gt; 1
oldNum &lt;span class="o"&gt;=&lt;/span&gt; 121
newNum &lt;span class="o"&gt;=&lt;/span&gt; 12
Check &lt;span class="k"&gt;if &lt;/span&gt;x is greater than 0 &lt;span class="o"&gt;(&lt;/span&gt;0&amp;lt;1&lt;span class="o"&gt;)&lt;/span&gt; ✅
    temp &lt;span class="o"&gt;=&lt;/span&gt; x % 10 &lt;span class="o"&gt;=&lt;/span&gt; 1 % 10 &lt;span class="o"&gt;=&lt;/span&gt; 1
    newNum &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;newNum &lt;span class="k"&gt;*&lt;/span&gt; 10&lt;span class="o"&gt;)&lt;/span&gt; + temp &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;12&lt;span class="k"&gt;*&lt;/span&gt;10&lt;span class="o"&gt;)&lt;/span&gt; + 1 &lt;span class="o"&gt;=&lt;/span&gt; 120 + 1 &lt;span class="o"&gt;=&lt;/span&gt; 121
    x &lt;span class="o"&gt;=&lt;/span&gt; x / 10 &lt;span class="o"&gt;=&lt;/span&gt; 1 / 10 &lt;span class="o"&gt;=&lt;/span&gt; 0

x &lt;span class="o"&gt;=&lt;/span&gt; 0
oldNum &lt;span class="o"&gt;=&lt;/span&gt; 121
newNum &lt;span class="o"&gt;=&lt;/span&gt; 121
Check &lt;span class="k"&gt;if &lt;/span&gt;x is greater than 0 &lt;span class="o"&gt;(&lt;/span&gt;0&amp;lt;0&lt;span class="o"&gt;)&lt;/span&gt; ❌

check &lt;span class="k"&gt;if &lt;/span&gt;oldNum is equal to newNum &lt;span class="o"&gt;(&lt;/span&gt;121 &lt;span class="o"&gt;==&lt;/span&gt; 121&lt;span class="o"&gt;)&lt;/span&gt; ✅
    &lt;span class="k"&gt;return &lt;/span&gt;&lt;span class="nb"&gt;true&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>design</category>
      <category>uidesign</category>
      <category>webdev</category>
      <category>frontend</category>
    </item>
    <item>
      <title>26. Remove Duplicates from Sorted Array</title>
      <dc:creator>Jyotirmoy Barman</dc:creator>
      <pubDate>Fri, 10 Feb 2023 19:04:43 +0000</pubDate>
      <link>https://dev.to/jyotirmoydotdev/26-remove-duplicates-from-sorted-array-k16</link>
      <guid>https://dev.to/jyotirmoydotdev/26-remove-duplicates-from-sorted-array-k16</guid>
      <description>&lt;h1&gt;
  
  
  Question
&lt;/h1&gt;

&lt;p&gt;Read the Question here &lt;a href="https://leetcode.com/problems/remove-duplicates-from-sorted-array/description/" rel="noopener noreferrer"&gt;https://leetcode.com/problems/remove-duplicates-from-sorted-array/description/&lt;/a&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  Answer
&lt;/h1&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;Input: nums &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;[&lt;/span&gt;1,1,2]
Output: 2, nums &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;[&lt;/span&gt;1,2,_]

Input: nums &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;[&lt;/span&gt;0,0,1,1,1,2,2,3,3,4]
Output: 5, nums &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;[&lt;/span&gt;0,1,2,3,4,_,_,_,_,_]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight cpp"&gt;&lt;code&gt;&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Solution&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
&lt;span class="nl"&gt;public:&lt;/span&gt;
    &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;removeDuplicates&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;vector&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&amp;amp;&lt;/span&gt; &lt;span class="n"&gt;nums&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;nums&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;size&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;j&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="n"&gt;j&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="n"&gt;nums&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;size&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt; &lt;span class="n"&gt;j&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;nums&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;!=&lt;/span&gt; &lt;span class="n"&gt;nums&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;j&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
                &lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
                &lt;span class="n"&gt;nums&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;nums&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;j&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;
            &lt;span class="p"&gt;}&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This algorithm will work only on sorted array .&lt;/p&gt;

&lt;p&gt;The function take a vector of integer (as a reference) and return an integer length of modifies vector after removing the duplicate integer. The function start with a if condition which check if the vector is empty and if it is true it will return 0 , if it is false and there is elements in vector it will continue. The algorithm uses two pointer &lt;code&gt;i&lt;/code&gt; and &lt;code&gt;j&lt;/code&gt; which itreate over the vector and and check for duplicate integers. The pointer &lt;code&gt;i&lt;/code&gt; starts with the first element and the for loop where &lt;code&gt;j&lt;/code&gt; starts with second element. Inside the for loop, if statement check if index &lt;code&gt;i&lt;/code&gt; element is not equal to index &lt;code&gt;j&lt;/code&gt; element, and if this is the case, this mean the index &lt;code&gt;j&lt;/code&gt; element is not duplicate of index &lt;code&gt;i&lt;/code&gt; element , so the element &lt;code&gt;j&lt;/code&gt; is assigned to &lt;code&gt;i&lt;/code&gt;+1. Then the pointer &lt;code&gt;i&lt;/code&gt; is increment with 1. This process continue till the end of the vector.&lt;/p&gt;

&lt;p&gt;At the end of the function, the pointer i+1 is returned as the length of the modified vector after removing duplicates.&lt;/p&gt;

&lt;p&gt;Its time complextity is O(n) as we are using only 1 for loop so the time complexity in depend on the size of the vector.&lt;/p&gt;

&lt;p&gt;This is how I debug, you can go through it to see what is happening in the code.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;vector -&amp;gt; 0 0 1 1 1 2 2 3 3 4
&lt;span class="nv"&gt;i&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;0    -&amp;gt; ↑
&lt;span class="nv"&gt;j&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;1    -&amp;gt;   ↑
&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;0!&lt;span class="o"&gt;=&lt;/span&gt;0&lt;span class="o"&gt;)&lt;/span&gt; ❌ 
&lt;span class="nt"&gt;----------------------------------------&lt;/span&gt;
Vector -&amp;gt; 0 0 1 1 1 2 2 3 3 4
&lt;span class="nv"&gt;i&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;0    -&amp;gt; ↑
&lt;span class="nv"&gt;j&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;2    -&amp;gt;     ↑
&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;0!&lt;span class="o"&gt;=&lt;/span&gt;1&lt;span class="o"&gt;)&lt;/span&gt; ✅
    Vector -&amp;gt; 0 0 1 1 1 2 2 3 3 4
    &lt;span class="nv"&gt;i&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;1    -&amp;gt;   ↑
    nums[i] &lt;span class="o"&gt;=&lt;/span&gt; nums[j]
    nums[1] &lt;span class="o"&gt;=&lt;/span&gt; nums[2]
        0   &lt;span class="o"&gt;=&lt;/span&gt;    1
    Vector modified &lt;span class="o"&gt;(&lt;/span&gt;0 is replaced with 1&lt;span class="o"&gt;)&lt;/span&gt;
                ↓
    Vector -&amp;gt; 0 1 1 1 1 2 2 3 3 4
&lt;span class="nt"&gt;----------------------------------------&lt;/span&gt;
Vector -&amp;gt; 0 1 1 1 1 2 2 3 3 4
&lt;span class="nv"&gt;i&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;1    -&amp;gt;   ↑
&lt;span class="nv"&gt;j&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;3    -&amp;gt;       ↑
&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;1!&lt;span class="o"&gt;=&lt;/span&gt;1&lt;span class="o"&gt;)&lt;/span&gt;❌
&lt;span class="nt"&gt;----------------------------------------&lt;/span&gt;
Vector -&amp;gt; 0 1 1 1 1 2 2 3 3 4
&lt;span class="nv"&gt;i&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;1    -&amp;gt;   ↑
&lt;span class="nv"&gt;j&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;4    -&amp;gt;         ↑
&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;1!&lt;span class="o"&gt;=&lt;/span&gt;1&lt;span class="o"&gt;)&lt;/span&gt; ❌
&lt;span class="nt"&gt;----------------------------------------&lt;/span&gt;
Vector -&amp;gt; 0 1 1 1 1 2 2 3 3 4
&lt;span class="nv"&gt;i&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;1    -&amp;gt;   ↑
&lt;span class="nv"&gt;j&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;5    -&amp;gt;           ↑
&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;1!&lt;span class="o"&gt;=&lt;/span&gt;2&lt;span class="o"&gt;)&lt;/span&gt;✅
    Vector -&amp;gt; 0 1 1 1 1 2 2 3 3 4 
    &lt;span class="nv"&gt;i&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;2    -&amp;gt;     ↑
    nums[i] &lt;span class="o"&gt;=&lt;/span&gt; nums[j]
    nums[2] &lt;span class="o"&gt;=&lt;/span&gt; nums[5]
        1   &lt;span class="o"&gt;=&lt;/span&gt;    2
    Vector modified &lt;span class="o"&gt;(&lt;/span&gt;1 is replaced with 2&lt;span class="o"&gt;)&lt;/span&gt;
                  ↓
    Vector -&amp;gt; 0 1 2 1 1 2 2 3 3 4
&lt;span class="nt"&gt;----------------------------------------&lt;/span&gt;
Vector -&amp;gt; 0 1 2 1 1 2 2 3 3 4
&lt;span class="nv"&gt;i&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;2    -&amp;gt;     ↑
&lt;span class="nv"&gt;j&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;6    -&amp;gt;             ↑
&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;2!&lt;span class="o"&gt;=&lt;/span&gt;2&lt;span class="o"&gt;)&lt;/span&gt; ❌
&lt;span class="nt"&gt;----------------------------------------&lt;/span&gt;
Vector -&amp;gt; 0 1 2 1 1 2 2 3 3 4
&lt;span class="nv"&gt;i&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;2    -&amp;gt;     ↑
&lt;span class="nv"&gt;j&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;7    -&amp;gt;               ↑
&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;2!&lt;span class="o"&gt;=&lt;/span&gt;3&lt;span class="o"&gt;)&lt;/span&gt;✅
    Vector -&amp;gt; 0 1 2 1 1 2 2 3 3 4 
    &lt;span class="nv"&gt;i&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;3    -&amp;gt;       ↑
    nums[i] &lt;span class="o"&gt;=&lt;/span&gt; nums[j]
    nums[3] &lt;span class="o"&gt;=&lt;/span&gt; nums[7]
        1   &lt;span class="o"&gt;=&lt;/span&gt;    3
    Vector modified &lt;span class="o"&gt;(&lt;/span&gt;1 is replaced with 3&lt;span class="o"&gt;)&lt;/span&gt;
                    ↓
    Vector -&amp;gt; 0 1 2 3 1 2 2 3 3 4
&lt;span class="nt"&gt;----------------------------------------&lt;/span&gt;
Vector -&amp;gt; 0 1 2 3 1 2 2 3 3 4
&lt;span class="nv"&gt;i&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;3    -&amp;gt;       ↑
&lt;span class="nv"&gt;j&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;8    -&amp;gt;                 ↑
&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;3!&lt;span class="o"&gt;=&lt;/span&gt;3&lt;span class="o"&gt;)&lt;/span&gt; ❌
&lt;span class="nt"&gt;----------------------------------------&lt;/span&gt;
Vector -&amp;gt; 0 1 2 3 1 2 2 3 3 4
&lt;span class="nv"&gt;i&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;3    -&amp;gt;       ↑
&lt;span class="nv"&gt;j&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;9    -&amp;gt;                   ↑
&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;3!&lt;span class="o"&gt;=&lt;/span&gt;4&lt;span class="o"&gt;)&lt;/span&gt;✅
    Vector -&amp;gt; 0 1 2 3 1 2 2 3 3 4 
    &lt;span class="nv"&gt;i&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;4    -&amp;gt;         ↑
    nums[i] &lt;span class="o"&gt;=&lt;/span&gt; nums[j]
    nums[4] &lt;span class="o"&gt;=&lt;/span&gt; nums[9]
        1   &lt;span class="o"&gt;=&lt;/span&gt;    4
    Vector modified &lt;span class="o"&gt;(&lt;/span&gt;1 is replaced with 4&lt;span class="o"&gt;)&lt;/span&gt;
                      ↓
    Vector -&amp;gt; 0 1 2 3 4 2 2 3 3 4
&lt;span class="nt"&gt;----------------------------------------&lt;/span&gt;
For Loop Stop
&lt;span class="nt"&gt;----------------------------------------&lt;/span&gt;

Answer
Vector -&amp;gt; 0 1 2 3 4 2 2 3 3 4
&lt;span class="k"&gt;return &lt;/span&gt;i+1 &lt;span class="o"&gt;=&lt;/span&gt; 5
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>discuss</category>
    </item>
    <item>
      <title>1. Two Sum</title>
      <dc:creator>Jyotirmoy Barman</dc:creator>
      <pubDate>Fri, 03 Feb 2023 06:24:05 +0000</pubDate>
      <link>https://dev.to/jyotirmoydotdev/1-two-sum-1b0b</link>
      <guid>https://dev.to/jyotirmoydotdev/1-two-sum-1b0b</guid>
      <description>&lt;h1&gt;
  
  
  Question
&lt;/h1&gt;

&lt;p&gt;Given an array of integers &lt;code&gt;nums&lt;/code&gt; and an integer &lt;code&gt;target&lt;/code&gt;, return &lt;em&gt;indices of the two numbers such that they add up to&lt;/em&gt; &lt;code&gt;target&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;You may assume that each input would have &lt;strong&gt;&lt;em&gt;exactly&lt;/em&gt; one solution&lt;/strong&gt;, and you may not use the &lt;em&gt;same&lt;/em&gt; element twice.&lt;/p&gt;

&lt;p&gt;You can return the answer in any order.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Example 1:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight xml"&gt;&lt;code&gt;Input: nums = [2,7,11,15], target = 9
Output: [0,1]
Explanation: Because nums[0] + nums[1] == 9, we return [0, 1].
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Example 2:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight xml"&gt;&lt;code&gt;Input: nums = [3,2,4], target = 6
Output: [1,2]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Example 3:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight xml"&gt;&lt;code&gt;Input: nums = [3,3], target = 6
Output: [0,1]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Constraints:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;2 &amp;lt;= nums.length &amp;lt;= 10&amp;lt;sup&amp;gt;4&amp;lt;/sup&amp;gt;&lt;/code&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;-10&amp;lt;sup&amp;gt;9&amp;lt;/sup&amp;gt; &amp;lt;= nums[i] &amp;lt;= 10&amp;lt;sup&amp;gt;9&amp;lt;/sup&amp;gt;&lt;/code&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;-10&amp;lt;sup&amp;gt;9&amp;lt;/sup&amp;gt; &amp;lt;= target &amp;lt;= 10&amp;lt;sup&amp;gt;9&amp;lt;/sup&amp;gt;&lt;/code&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Only one valid answer exists.&lt;/strong&gt;&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h1&gt;
  
  
  Answer
&lt;/h1&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight cpp"&gt;&lt;code&gt;&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Solution&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
&lt;span class="nl"&gt;public:&lt;/span&gt;
    &lt;span class="n"&gt;vector&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;twoSum&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;vector&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&amp;amp;&lt;/span&gt; &lt;span class="n"&gt;nums&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;target&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="n"&gt;vector&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;ans&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
      &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;&lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;nums&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;size&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;&lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt;&lt;span class="p"&gt;){&lt;/span&gt;
        &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;j&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="o"&gt;+&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;&lt;span class="n"&gt;j&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;nums&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;size&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;&lt;span class="n"&gt;j&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt;&lt;span class="p"&gt;){&lt;/span&gt;
            &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="n"&gt;nums&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="o"&gt;+&lt;/span&gt;&lt;span class="n"&gt;nums&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;j&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt;&lt;span class="o"&gt;==&lt;/span&gt;&lt;span class="n"&gt;target&lt;/span&gt;&lt;span class="p"&gt;){&lt;/span&gt;
                &lt;span class="n"&gt;ans&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;push_back&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
                &lt;span class="n"&gt;ans&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;push_back&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;j&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
            &lt;span class="p"&gt;}&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt; 
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;ans&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; 
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The solution we will be using is brute force, the function takes two variables one is nums which contain the vector and the other one is a target which we need to find by summing two indexes in the vector and if we got the sum we will return the index in a new vector.&lt;/p&gt;

&lt;p&gt;Before we start the for loops first we need to make an empty vector, which we will call &lt;code&gt;ans&lt;/code&gt;. we will use a nested for loop to check if the target is present in the array. The first loop starts with the i'th which is 0 and stops at (vector size - 1) and the inner for loop starts at i+1 and stops as same as (vector size -1), if the index i and i+n (where n is a number less than vector size but greater than i) is equal to the target value we will push the index to the new array &lt;code&gt;ans&lt;/code&gt; and return it. It has O(n^2) time complexity as it has two nested loops. Below you can see an animation of how this program works.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1674166201237%2F530d630d-4026-40e8-b755-76cfadc4027d.gif%2520align%3D" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1674166201237%2F530d630d-4026-40e8-b755-76cfadc4027d.gif%2520align%3D" width="800" height="400"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
      <category>discuss</category>
    </item>
    <item>
      <title>Set up Tailwind in your Project</title>
      <dc:creator>Jyotirmoy Barman</dc:creator>
      <pubDate>Thu, 02 Feb 2023 05:28:39 +0000</pubDate>
      <link>https://dev.to/jyotirmoydotdev/set-up-tailwind-in-your-project-3nd7</link>
      <guid>https://dev.to/jyotirmoydotdev/set-up-tailwind-in-your-project-3nd7</guid>
      <description>&lt;p&gt;Tailwind CSS is a utility class framework that helps you make a responsive web design. In this article, I will teach you, how to set up a tailwind in the project.&lt;/p&gt;

&lt;h2&gt;
  
  
  Play CDN ( Method 1)
&lt;/h2&gt;

&lt;p&gt;This is the easiest way to use Tailwind, but it is not recommended for a production application. &lt;code&gt;&amp;lt;script src="https://cdn.tailwindcss.com"&amp;gt;&amp;lt;/script&amp;gt;&lt;/code&gt; inside the &lt;code&gt;&amp;lt;head&amp;gt;&lt;/code&gt; tag.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;An Internet connection is required!&lt;br&gt;
&lt;/p&gt;
&lt;/blockquote&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight xml"&gt;&lt;code&gt;&lt;span class="cp"&gt;&amp;lt;!doctype html&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;html&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;head&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;meta&lt;/span&gt; &lt;span class="na"&gt;charset=&lt;/span&gt;&lt;span class="s"&gt;"UTF-8"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;meta&lt;/span&gt; &lt;span class="na"&gt;name=&lt;/span&gt;&lt;span class="s"&gt;"viewport"&lt;/span&gt; &lt;span class="na"&gt;content=&lt;/span&gt;&lt;span class="s"&gt;"width=device-width, initial-scale=1.0"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;script&lt;/span&gt; &lt;span class="na"&gt;src=&lt;/span&gt;&lt;span class="s"&gt;"https://cdn.tailwindcss.com"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&amp;lt;/script&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/head&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;body&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;h1&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"text-3xl font-bold underline"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
    Hello world!
  &lt;span class="nt"&gt;&amp;lt;/h1&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/body&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/html&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Tailwind CLI ( Method 2 )
&lt;/h2&gt;

&lt;p&gt;Tailwind CLI is a tool to quickly set up your project a generate required styling automatically. First You need to install node.js on your computer. After you have installed Node.js creates a folder (&lt;code&gt;Tailwind-Project&lt;/code&gt;) and run the below command on your terminal.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Internet connection is not required after you have done the setup once!&lt;br&gt;
&lt;/p&gt;
&lt;/blockquote&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;mkdir &lt;/span&gt;Tailwind-Project
&lt;span class="nb"&gt;cd &lt;/span&gt;Tailwind-Project
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npm &lt;span class="nb"&gt;install&lt;/span&gt; &lt;span class="nt"&gt;-D&lt;/span&gt; tailwindcss
npx tailwindcss init
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;After you have run the above command you will see a &lt;code&gt;tailwind.config.js&lt;/code&gt; file in your folder.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;➜  Tailwind-Project tree
&lt;span class="nb"&gt;.&lt;/span&gt;
└── tailwind.config.js

0 directories, 1 file
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Create a &lt;code&gt;src&lt;/code&gt; folder inside &lt;code&gt;Tailwind-Project&lt;/code&gt; and add your HTML, CSS, and Javascript files inside it.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;bash
➜  Tailwind-Project tree
.
├── src
│   ├── input.css
│   ├── main.html
│   └── main.js
└── tailwind.config.js

1 directory, 4 files
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now it is time for configuring &lt;code&gt;tailwind.config.js&lt;/code&gt; you will something just like this in the code.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;javascript
module.exports = {
  content: [],
  theme: {
    extend: {},
  },
  plugins: [],
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Replace or Rewrite the code with this ↓. Here are adding the paths to all of your template files in your &lt;code&gt;tailwind.config.js&lt;/code&gt; file.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="cm"&gt;/** @type {import('tailwindcss').Config} */&lt;/span&gt;
&lt;span class="nx"&gt;module&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;exports&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="na"&gt;content&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;./src/**/*.{html,js}&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;
  &lt;span class="na"&gt;theme&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="na"&gt;extend&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{},&lt;/span&gt;
  &lt;span class="p"&gt;},&lt;/span&gt;
  &lt;span class="na"&gt;plugins&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[],&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Open the &lt;code&gt;input.css&lt;/code&gt; file and paste the below lines.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="k"&gt;@tailwind&lt;/span&gt; &lt;span class="n"&gt;base&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;@tailwind&lt;/span&gt; &lt;span class="n"&gt;components&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;@tailwind&lt;/span&gt; &lt;span class="n"&gt;utilities&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now run this command to start the Tailwind CLI build process, it will generate a file under a &lt;code&gt;/dist/output.css&lt;/code&gt; , and here is the file which will contain all your CSS styling.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npx tailwindcss &lt;span class="nt"&gt;-i&lt;/span&gt; ./src/input.css &lt;span class="nt"&gt;-o&lt;/span&gt; ./dist/output.css &lt;span class="nt"&gt;--watch&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now you will see something just like this.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;warn - The &lt;span class="sb"&gt;`&lt;/span&gt;content&lt;span class="sb"&gt;`&lt;/span&gt; option &lt;span class="k"&gt;in &lt;/span&gt;your Tailwind CSS configuration is missing or empty.
warn - Configure your content sources or your generated CSS will be missing styles.
warn - https://tailwindcss.com/docs/content-configuration
Browserslist: caniuse-lite is outdated. Please run:
  npx browserslist@latest &lt;span class="nt"&gt;--update-db&lt;/span&gt;
  Why you should &lt;span class="k"&gt;do &lt;/span&gt;it regularly: https://github.com/browserslist/browserslist#browsers-data-updating

Rebuilding...
Done &lt;span class="k"&gt;in &lt;/span&gt;88ms.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now the project structure should see like this. Here you will see a new file under the folder &lt;code&gt;dist&lt;/code&gt; the file name will be &lt;code&gt;output.css&lt;/code&gt;. This is a file that we need to insert into our HTML.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;➜  Tailwind-Project tree
&lt;span class="nb"&gt;.&lt;/span&gt;
├── dist
│   └── output.css
├── src
│   ├── input.css
│   ├── main.html
│   └── main.js
└── tailwind.config.js

2 directories, 5 files
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Paste the below command into your HTML file (&lt;code&gt;main.html&lt;/code&gt;). The line &lt;code&gt;&amp;lt;link href="/dist/output.css" rel="stylesheet"&amp;gt;&lt;/code&gt; is the line that links &lt;code&gt;output.css&lt;/code&gt; to &lt;code&gt;main.html&lt;/code&gt; . Now you can write class can the Tailwind CLI will automatically build the CSS file.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;xml
&amp;lt;!doctype html&amp;gt;
&amp;lt;html&amp;gt;
&amp;lt;head&amp;gt;
  &amp;lt;meta charset="UTF-8"&amp;gt;
  &amp;lt;meta name="viewport" content="width=device-width, initial-scale=1.0"&amp;gt;
  &amp;lt;link href="/dist/output.css" rel="stylesheet"&amp;gt;
&amp;lt;/head&amp;gt;
&amp;lt;body&amp;gt;
  &amp;lt;h1 class="text-3xl font-bold underline"&amp;gt;
    Hello world!
  &amp;lt;/h1&amp;gt;
&amp;lt;/body&amp;gt;
&amp;lt;/html&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To learn how to use Tailwind CSS head over to &lt;a href="https://tailwindcss.com" rel="noopener noreferrer"&gt;tailwindcss.com&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Follow me on Twitter &lt;a href="https://twitter.com/jyotirmoydotdev/" rel="noopener noreferrer"&gt;Jyotirmoy Barman&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>crypto</category>
      <category>blockchain</category>
      <category>web3</category>
      <category>offers</category>
    </item>
    <item>
      <title>NAPPTIVE made Cloud-Native Easy 🤯</title>
      <dc:creator>Jyotirmoy Barman</dc:creator>
      <pubDate>Thu, 02 Feb 2023 05:17:40 +0000</pubDate>
      <link>https://dev.to/jyotirmoydotdev/napptive-made-cloud-native-easy-26da</link>
      <guid>https://dev.to/jyotirmoydotdev/napptive-made-cloud-native-easy-26da</guid>
      <description>&lt;h1&gt;
  
  
  Introduction
&lt;/h1&gt;

&lt;p&gt;First, let me talk about why we need to run the application on the cloud, let's take an example of a static website, which contains &lt;code&gt;index.html&lt;/code&gt; we can run this file on our computer or we can say local host, but this website only can be accessed by you, and other people on the internet cannot access it. You can run a server on your computer which will expose your local host to the internet but you need to run your computer 24X7 so other people access your website, which is not practical for most of us, but what we can do? we can use a cloud provider or you can say a person who is giving their computer to run the program 24X7. Now people can access your &lt;code&gt;index.html&lt;/code&gt; file at any time and from any computer.&lt;/p&gt;

&lt;p&gt;Now we understood why we need a cloud, but one more problem arises the pain of configuring and handling the traffic and learning docker, Kubernetes, etc., But if you are a developer who just wants to focus on your work, like improving the application. So, we can use Napptive to help us with all these 👍.&lt;/p&gt;

&lt;p&gt;Did You ask What is Napptive?🤔 I am here to explain.&lt;/p&gt;

&lt;p&gt;NAPPTIVE is a cloud-native application platform. It is a platform that provides an integrated solution that can be used by developers and non-technical users. Enough of the description, let us try this platform.&lt;/p&gt;

&lt;h1&gt;
  
  
  Deploy Static Website
&lt;/h1&gt;

&lt;p&gt;To deploy a static website first, we need to upload the code to GitHub, for now, we will use the repository &lt;a href="https://github.com/napptive/static-example-launcher-app" rel="noopener noreferrer"&gt;github.com/napptive/static-example-launcher-app&lt;/a&gt; or you can use yours. Make sure to login into your Napptive account, you can use an Email, Google, or GitHub account, and after that choose a username [user name should be in lowercase and without space] for your login. Now login to your account with your chosen login method. After you have logged in you can see something just like this :&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1675292476863%2F5e137e73-3c8b-4d6a-9f07-316535c8a81b.png%2520align%3D" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1675292476863%2F5e137e73-3c8b-4d6a-9f07-316535c8a81b.png%2520align%3D" alt="Napptive dashboard"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You can see a tutorial pop up, you can read it. As you can see, this is the dashboard where you can maintain your apps. NAPPTIVE provides a catalog where can you simply set up your project, and click on the top left corner second option &lt;strong&gt;Catalog&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1675293018036%2Ffd5072a2-5700-4bd0-a208-8519d62a2a9c.png%2520align%3D" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1675293018036%2Ffd5072a2-5700-4bd0-a208-8519d62a2a9c.png%2520align%3D"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Click the &lt;strong&gt;deploy-static-app&lt;/strong&gt; after that click on ► &lt;strong&gt;Deploy :&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1675293244740%2F54aa0f07-5eaa-4166-9f55-8df24b0d2210.png%2520align%3D" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1675293244740%2F54aa0f07-5eaa-4166-9f55-8df24b0d2210.png%2520align%3D"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;After you have clicked it, you can see a YAML code inside the &lt;strong&gt;Components configuration,&lt;/strong&gt; here we need to configure the code if you want to deploy your own code but as I have said I will deploy the default code.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1675293463511%2Fc650eb7f-8b59-41de-85cd-8b3fadc182d0.png%2520align%3D" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1675293463511%2Fc650eb7f-8b59-41de-85cd-8b3fadc182d0.png%2520align%3D"&gt;&lt;/a&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="na"&gt;components&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
    &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;deploy-static-comp&lt;/span&gt;
      &lt;span class="na"&gt;type&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;webservice&lt;/span&gt;
      &lt;span class="na"&gt;properties&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
        &lt;span class="na"&gt;image&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;napptive/playground-launcher-static-nginx:1.22-v1.0.0&lt;/span&gt;
        &lt;span class="na"&gt;cpu&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="s"&gt;100m"&lt;/span&gt;
        &lt;span class="na"&gt;memory&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;128Mi&lt;/span&gt;
        &lt;span class="na"&gt;ports&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
            &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;port&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="m"&gt;80&lt;/span&gt;
              &lt;span class="na"&gt;expose&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;
&lt;span class="c1"&gt;#-------------------------------------------------------------------&lt;/span&gt;
        &lt;span class="na"&gt;env&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
            &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;LAUNCHER_TARGET_REPO&lt;/span&gt; &lt;span class="c1"&gt;# target_repo&lt;/span&gt;
              &lt;span class="na"&gt;value&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;https://github.com/napptive/static-example-launcher-app.git&lt;/span&gt;
&lt;span class="c1"&gt;#-------------------------------------------------------------------&lt;/span&gt;
            &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;LAUNCHER_REPOSITORY_USER&lt;/span&gt;
              &lt;span class="na"&gt;value&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="s"&gt;"&lt;/span&gt;

            &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;LAUNCHER_REPOSITORY_ACCESS_TOKEN&lt;/span&gt;
              &lt;span class="na"&gt;value&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="s"&gt;"&lt;/span&gt;
&lt;span class="err"&gt;      &lt;/span&gt;&lt;span class="na"&gt;traits&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="c1"&gt;# Trait section&lt;/span&gt;
        &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;type&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;napptive-ingress&lt;/span&gt;
          &lt;span class="na"&gt;properties&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
            &lt;span class="na"&gt;port&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="m"&gt;80&lt;/span&gt;
            &lt;span class="na"&gt;path&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;/&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here you can see the lien I have hilited, you need to change the &lt;strong&gt;value:&lt;/strong&gt; link with your GitHub repo link, and you can give any &lt;strong&gt;name:&lt;/strong&gt; to your app. After you have done you can see the ► &lt;strong&gt;Deploy&lt;/strong&gt; button in the bottom right corner, click it. Conformation is asked just click &lt;strong&gt;► Yes. deploy.&lt;/strong&gt; After you have clicked you can see a new app in your dashboard.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1675294304097%2F03fa7922-b0a9-4ca8-aa99-edf6fef1fcc7.png%2520align%3D" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1675294304097%2F03fa7922-b0a9-4ca8-aa99-edf6fef1fcc7.png%2520align%3D"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;First, the CPU was using 0% but now you can see we are using 10% of the CPU and 3% of ram, remember different projects can use a different amount of resources. Free users have &lt;strong&gt;1 CPU, 4000 MB RAM,&lt;/strong&gt; and &lt;strong&gt;1000 MB RAM.&lt;/strong&gt; If you need more ram you can upgrade to the &lt;strong&gt;PRO&lt;/strong&gt; plan.&lt;/p&gt;

&lt;p&gt;Now, Check the deployment, you can access the deployment with the link which is in the section &lt;strong&gt;endpoints&lt;/strong&gt; for me the link is &lt;a href="http://deploy-static-comp-80-cfdakufl20br8thb27s0.apps.playground.napptive.dev" rel="noopener noreferrer"&gt;deploy-static-comp-80-cfdakufl20br8thb27s0.apps.playground.napptive.dev&lt;/a&gt;, you can also go to this link and check this website.&lt;/p&gt;

&lt;p&gt;To study more read the doc :&lt;br&gt;&lt;br&gt;
&lt;a href="https://docs.napptive.com/tutorials/Deploying_Drawio.html" rel="noopener noreferrer"&gt;https://docs.napptive.com/tutorials/Deploying_Drawio.html&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Just Like this, you can deploy &lt;strong&gt;Python Apps,&lt;/strong&gt; &lt;strong&gt;NodeJs Apps,&lt;/strong&gt; &lt;strong&gt;WordPress,&lt;/strong&gt; and many more.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Remove Even Integers From an Array</title>
      <dc:creator>Jyotirmoy Barman</dc:creator>
      <pubDate>Mon, 02 Jan 2023 21:18:24 +0000</pubDate>
      <link>https://dev.to/jyotirmoydotdev/remove-even-integers-from-an-array-2hk</link>
      <guid>https://dev.to/jyotirmoydotdev/remove-even-integers-from-an-array-2hk</guid>
      <description>&lt;p&gt;Implement a function &lt;code&gt;RemoveEven( int *&amp;amp; arr, int n )&lt;/code&gt; which takes an array &lt;code&gt;arr&lt;/code&gt; and its size and removes all the even elements from a given array.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Input&lt;/strong&gt;&lt;/p&gt;


&lt;pre class="highlight cpp"&gt;&lt;code&gt;&lt;span class="mi"&gt;5&lt;/span&gt;
&lt;span class="mi"&gt;1&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt; &lt;span class="mi"&gt;4&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;


&lt;p&gt;&lt;strong&gt;Output&lt;/strong&gt;&lt;/p&gt;


&lt;pre class="highlight cpp"&gt;&lt;code&gt;&lt;span class="mi"&gt;1&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/blockquote&gt;

&lt;h1&gt;
  
  
  Solution
&lt;/h1&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight cpp"&gt;&lt;code&gt;&lt;span class="cp"&gt;#include&lt;/span&gt;&lt;span class="cpf"&gt;&amp;lt;iostream&amp;gt;&lt;/span&gt;&lt;span class="cp"&gt;
&lt;/span&gt;&lt;span class="k"&gt;using&lt;/span&gt; &lt;span class="k"&gt;namespace&lt;/span&gt; &lt;span class="n"&gt;std&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;NewArraySize&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="nf"&gt;RemoveEven&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="o"&gt;*&amp;amp;&lt;/span&gt; &lt;span class="n"&gt;arr&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;n&lt;/span&gt;&lt;span class="p"&gt;){&lt;/span&gt;
    &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="n"&gt;NewArray&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt;&lt;span class="p"&gt;[]{};&lt;/span&gt;
    &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;&lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;n&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;&lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt;&lt;span class="p"&gt;){&lt;/span&gt;
        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="n"&gt;arr&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="o"&gt;%&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="o"&gt;==&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;){&lt;/span&gt;
            &lt;span class="n"&gt;NewArray&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;NewArraySize&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;arr&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="k"&gt;delete&lt;/span&gt; &lt;span class="p"&gt;[]&lt;/span&gt; &lt;span class="n"&gt;arr&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="n"&gt;arr&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;NewArray&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;arr&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="nf"&gt;main&lt;/span&gt;&lt;span class="p"&gt;(){&lt;/span&gt;
        &lt;span class="c1"&gt;// Array size&lt;/span&gt;
    &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;n&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="n"&gt;cin&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&amp;gt;&lt;/span&gt;&lt;span class="n"&gt;n&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

        &lt;span class="c1"&gt;// Array&lt;/span&gt;
    &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="n"&gt;arr&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;n&lt;/span&gt;&lt;span class="p"&gt;]{};&lt;/span&gt;
        &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;&lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;n&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;&lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt;&lt;span class="p"&gt;){&lt;/span&gt;
                &lt;span class="n"&gt;cin&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&amp;gt;&lt;/span&gt;&lt;span class="n"&gt;arr&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;

        &lt;span class="c1"&gt;// Calling the funciton&lt;/span&gt;
    &lt;span class="n"&gt;arr&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;RemoveEven&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;arr&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="n"&gt;n&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

        &lt;span class="c1"&gt;// Printing the new array&lt;/span&gt;
    &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;&lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;NewArraySize&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;&lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt;&lt;span class="p"&gt;){&lt;/span&gt;
        &lt;span class="n"&gt;cout&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;arr&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&amp;lt;&lt;/span&gt;&lt;span class="s"&gt;" "&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="n"&gt;cout&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;endl&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here inside the function &lt;code&gt;RemoveEven()&lt;/code&gt;we created a new dynamic array &lt;code&gt;NewArray&lt;/code&gt;which will be used to store the &lt;strong&gt;odd&lt;/strong&gt; element. Next, we are using a &lt;strong&gt;for loop&lt;/strong&gt; to check if an element in an array of index i is odd or even if the reminder is 1 then it is an odd number, it will be pushed in the &lt;code&gt;NewArray&lt;/code&gt; and then the variable &lt;code&gt;NewArraySize&lt;/code&gt; will be + 1 so we can keep track of the size of the array as we can’t get the dynamic array size with &lt;code&gt;sizeof()&lt;/code&gt; function. After, we have successfully added all the odd number elements in the &lt;code&gt;NewArray&lt;/code&gt; we will delete all the elements of the &lt;code&gt;arr&lt;/code&gt; as we want to copy the &lt;code&gt;NewArray&lt;/code&gt; elements in &lt;code&gt;arr&lt;/code&gt; and then return it.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Run the code with &lt;code&gt;g++ -std=c++20 fileName.cpp -o a.out&lt;/code&gt; and &lt;code&gt;./a.out&lt;/code&gt;&lt;/p&gt;
&lt;/blockquote&gt;

</description>
      <category>emptystring</category>
    </item>
    <item>
      <title>Compile and Run C++ file with single custom command</title>
      <dc:creator>Jyotirmoy Barman</dc:creator>
      <pubDate>Wed, 02 Nov 2022 21:54:41 +0000</pubDate>
      <link>https://dev.to/jyotirmoydotdev/compile-and-run-c-file-with-single-custom-command-3aol</link>
      <guid>https://dev.to/jyotirmoydotdev/compile-and-run-c-file-with-single-custom-command-3aol</guid>
      <description>&lt;p&gt;I this article I am going to show how you can write your own custom command in terminal. For the purpose of explanation &lt;strong&gt;I am going to show how you can build any run a C++ File with just a single command&lt;/strong&gt; .&lt;/p&gt;

&lt;p&gt;First check if you have intsall the g++ compiler in your computer or not, to check it run this command, it will show the version of your g++ compiler. If it shows you ther version you are ready to go.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;g++ --version
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Open your Terminal App in Mac, and type &lt;code&gt;cd&lt;/code&gt; this will bring you &lt;code&gt;~&lt;/code&gt; or &lt;code&gt;/Users/YourUserName&lt;/code&gt; folder. &lt;/p&gt;

&lt;p&gt;In this folder you need to make a new file in which you want to write the command . For this example I am giving the file name &lt;code&gt;.custom_command.sh&lt;/code&gt;, now let us understand the file name as you can see I have given a &lt;code&gt;.&lt;/code&gt; in-front of the file name, dot will hide the file and save from accidental delete. In place of &lt;code&gt;custom_command&lt;/code&gt; you can give any file name and the file ends with the extension &lt;code&gt;.sh&lt;/code&gt; which is shell script.&lt;/p&gt;

&lt;p&gt;This command will make the file.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;touch .custom_command.sh
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now, We need to write the Script inside this file, open the file with vim.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;vim .custom_command.sh
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now press &lt;code&gt;I&lt;/code&gt; on vim and copy the code below and paste it in the file. After you have pasted the code hit &lt;code&gt;esc&lt;/code&gt; and write &lt;code&gt;:wq&lt;/code&gt; and hit enter this will save the file changes.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;#!/bin/bash

function run(){
        if g++ -std=c++20 $1 -o runed; then
        ./runed
        else
                echo 'Error in '$1
        fi
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Code Explanation
&lt;/h2&gt;

&lt;p&gt;First Line &lt;code&gt;#!/bin/bash&lt;/code&gt; says that with which we need interact, I our case we are interacting with the bash.&lt;/p&gt;

&lt;p&gt;Second we have made a function with the name of &lt;code&gt;run&lt;/code&gt; this is the command with which we will compile and run the c++ file at the same time. For an example we have a C++ file name print_helloworld.cpp which output &lt;code&gt;HelloWorld!&lt;/code&gt;, first we need to compile it and then run it but with the custom command we can do the both with just one command.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;run print_helloworld.cpp
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You can give your own function name, replace the &lt;code&gt;run&lt;/code&gt; with your own desired word in the &lt;code&gt;.custom_command.sh&lt;/code&gt; file, for an example if your replace the &lt;code&gt;run&lt;/code&gt; with &lt;code&gt;runcpp&lt;/code&gt; than you need to type the below code to run the C++ file.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;runcpp print_helloworld.cpp
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now Coming on the third line, as you can see the code if inside if loop ( the loop basically says if the file compile then run the compiled code or else print a error message ). We need to see the line which says &lt;code&gt;g++ -std=c++20 $1 -o runed&lt;/code&gt; this mean that we are using a g++ compiler to compile our c++ code and we are using c++ version 20 '-std=c++20' after which we are taking an input &lt;code&gt;$1&lt;/code&gt; which is the file name and creating a new file &lt;code&gt;-o runed&lt;/code&gt; in which we will have our complied code. &lt;/p&gt;

&lt;p&gt;If the file compiled successfully then it will run the code with the line &lt;code&gt;./runned&lt;/code&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Back to Setup
&lt;/h2&gt;

&lt;p&gt;After you have successfully made the file &lt;code&gt;.custom_command.sh&lt;/code&gt; open ~/.bashrc with vim if you use Bash or ~/.zshrc if you use ZSH and paste the below command at the last, this will allow to run your command from any session or terminal window.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;source ~/.custom_command.sh
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;Notice : If you have changed the file name in which you have written the custom command then replace the &lt;code&gt;.custom_command.sh&lt;/code&gt; with your file name.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Now hit &lt;code&gt;esc&lt;/code&gt; and then type &lt;code&gt;:wq&lt;/code&gt; and then hit enter. The file has been saved. Now restart you terminal.&lt;/p&gt;

&lt;h2&gt;
  
  
  Test The Command
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;run print_helloworld.cpp
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If you like the article then hit the like button and follow me on twitter for my latest update &lt;a href="https://twitter.com/jyotirmoydotdev"&gt;@jyotirmoydotdev&lt;/a&gt;.&lt;/p&gt;

</description>
    </item>
  </channel>
</rss>
