<?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: Hargunbeer Singh</title>
    <description>The latest articles on DEV Community by Hargunbeer Singh (@hamiecod).</description>
    <link>https://dev.to/hamiecod</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%2F490192%2F823a031c-a218-4414-a036-7c6ebc751586.jpg</url>
      <title>DEV Community: Hargunbeer Singh</title>
      <link>https://dev.to/hamiecod</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/hamiecod"/>
    <language>en</language>
    <item>
      <title>How do structs work internally?</title>
      <dc:creator>Hargunbeer Singh</dc:creator>
      <pubDate>Wed, 29 Dec 2021 09:00:19 +0000</pubDate>
      <link>https://dev.to/hamiecod/how-do-structs-work-internally-3ea7</link>
      <guid>https://dev.to/hamiecod/how-do-structs-work-internally-3ea7</guid>
      <description>&lt;h2&gt;
  
  
  Table of Contents
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Abstract&lt;/li&gt;
&lt;li&gt;Table of Contents&lt;/li&gt;
&lt;li&gt;Introduction&lt;/li&gt;
&lt;li&gt;
Memory Alignment

&lt;ul&gt;
&lt;li&gt;Structure Padding&lt;/li&gt;
&lt;li&gt;Aligned Structs&lt;/li&gt;
&lt;li&gt;Advantages&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;/ul&gt;

&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;Structs are low-level data structures that store complex data structures. A struct consists of multiple fields that store data of different or the same data types. Structs are similar to arrays in some ways. Like arrays, the data of a struct is stored in a contiguous block of memory. &lt;/p&gt;

&lt;p&gt;The variable to which an array is assigned becomes a reference variable to the first element of the array. Likewisely, the variable to which a struct is assigned becomes a reference variable to the first field of the struct. In arrays, you can navigate through the elements by adding the size of an element to the address of the first element. &lt;/p&gt;

&lt;p&gt;For example, you can get the second element of an integer array by adding &lt;code&gt;4&lt;/code&gt; to the memory address of the first element and you can do the same procedure multiple times to get consequent elements. The process of navigating through the fields of a struct is similar to arrays. Theoretically, you just need to add the size of the first field to its memory address to get the memory address of the second field. This is theoretical because it is not as simple practically.&lt;/p&gt;

&lt;h2&gt;
  
  
  Memory alignment
&lt;/h2&gt;

&lt;p&gt;Memory alignment is the process of aligning the data in memory in such a way that is efficient and favorable for the processor. Data is aligned in memory by padding the data. Padding the data means adding some empty bits to the head or the tail of data in order to align it properly. There are some rules for structure alignment. Structure alignment is achieved by structure padding and both the processes complement each other.&lt;/p&gt;

&lt;h3&gt;
  
  
  Structure Padding
&lt;/h3&gt;

&lt;p&gt;The memory alignment of the structure depends on the structure padding. The alignment and padding change according to the size of the various fields of a struct. There are two main rules to determine the padding and the alignment of the struct. To explain both the rules we would take the following struct as an example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight c"&gt;&lt;code&gt;&lt;span class="k"&gt;struct&lt;/span&gt; &lt;span class="n"&gt;example&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kt"&gt;char&lt;/span&gt; &lt;span class="n"&gt;i&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="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="n"&gt;example1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We need to know the size of the various fields of the struct to determine the structure padding. The compiler knows the size of the fields by their particular data type. The field &lt;code&gt;i&lt;/code&gt; is of 1 byte because it is a &lt;code&gt;char&lt;/code&gt;. The field &lt;code&gt;j&lt;/code&gt; is of 4 bytes because it is an &lt;code&gt;int&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;The offset of a field of a struct is the amount of memory between its memory address and the memory address of the first field of the struct. In the struct mentioned above, the offset of &lt;code&gt;j&lt;/code&gt; is &lt;code&gt;1&lt;/code&gt; because there is 1 byte memory between the memory address of &lt;code&gt;i&lt;/code&gt; and its own memory address.&lt;/p&gt;

&lt;p&gt;The first rule of structure padding requires the offset of a field to be divisible by the size of the same field. For example, in the above mentioned struct the offset of &lt;code&gt;j&lt;/code&gt; must be divisible by its size(4 bytes). For making its offset divisible by its own size, we need to add padding in between &lt;code&gt;i&lt;/code&gt; and &lt;code&gt;j&lt;/code&gt;. So to make the offset divisible by 4, we need to add 3 bytes of padding. So, there is 3 bytes of padding in between &lt;code&gt;i&lt;/code&gt; and &lt;code&gt;j&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;The second rule of structure padding requires the size of the struct to be divisible by the size of the largest field of the struct. For example, consider the following struct:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight c"&gt;&lt;code&gt;&lt;span class="k"&gt;struct&lt;/span&gt; &lt;span class="n"&gt;dog&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;person&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="n"&gt;owner&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;age&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="n"&gt;bruno&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The first field of the above struct is a pointer to another struct so its size is 8 bytes. The size of the second field is 4 bytes because it is an integer. No padding is needed in between &lt;code&gt;owner&lt;/code&gt; and &lt;code&gt;age&lt;/code&gt; because the offset of &lt;code&gt;age&lt;/code&gt; is 8 bytes which is divisible by its size 4.&lt;/p&gt;

&lt;p&gt;The second rule requires us to add padding at the end of the struct. The size of the struct(8+4=12) is not divisible by the size of the largest field of the struct(8 bytes). So to make its size divisible by 8, we will have to add padding at the end of the struct. We need to add 4 bytes of padding to make its new size divisible by 8. After adding 4 bytes of padding, its new size, i.e. 16 bytes is divisible by 8 hence following the second rule of structure padding.&lt;/p&gt;

&lt;h3&gt;
  
  
  Aligned structs
&lt;/h3&gt;

&lt;p&gt;Data needs to be aligned properly for efficiency and performance of processors. If you have a 8-byte sized field in a struct, you should place it at a memory address divisible by 8. If you do not do so, the data stored in that 8-byte field would be called misaligned. Reading misaligned data is slow for the processor and the processor might not support a misaligned value, resulting in  a program crash.&lt;/p&gt;

&lt;p&gt;The first rule for structure padding requires the offset of the 8 byte sized field to be divisible by 8. You might need to add padding to make its offset divisible by 8. Suppose you have an integer before the 8-byte sized field. You would add 4 bytes of padding to make the offset divisible by 8. In this process, you have also made the memory address of the integer divisible by 8.&lt;/p&gt;

&lt;p&gt;So in the process of making a field aligned at a memory address divisible by its size, you have aligned the struct by storing it at a memory address divisible by its alignment(the size of the largest field of the struct). The struct is considered to be stored at a memory address divisibly by 8 when its first field is stored at a memory address divisible by 8.&lt;/p&gt;

&lt;h3&gt;
  
  
  Advantages
&lt;/h3&gt;

&lt;p&gt;There are a lot of advantages of memory alignment. Most processors work the best on memory aligned data. Memory alignment in structs is very advantageous because it prevents a struct field or a struct to be stored across two memory blocks. Fetching data from multiple memory blocks is very inefficient for the processor.&lt;/p&gt;

&lt;p&gt;Also, the storing of data over two memory blocks might also chop the data. For example you are storing an array of structs in which the struct consists of a pointer and an integer. The struct is misaligned and has a size of 9 bytes. In case the array contains a lot of data, eventually the memory would all be used and the last instance of the struct would be chopped because there would be &lt;br&gt;
likely no memory address divisibly by 9.&lt;/p&gt;

&lt;h2&gt;
  
  
  Bibiliography
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;a href="https://www.reddit.com/r/computerscience/comments/rj8mre/how_do_structs_work_internally/" rel="noopener noreferrer"&gt;A reddit post about structs in r/computerscience&lt;/a&gt;

&lt;ul&gt;
&lt;li&gt;Special thanks to u/AuntieSauce, u/Poddster and u/JojoModding who helped me out in understanding the internal workings of structs&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;/ul&gt;

</description>
    </item>
    <item>
      <title>Remainder VS Modulus</title>
      <dc:creator>Hargunbeer Singh</dc:creator>
      <pubDate>Sun, 12 Dec 2021 09:27:55 +0000</pubDate>
      <link>https://dev.to/hamiecod/remainder-vs-modulus-3mc8</link>
      <guid>https://dev.to/hamiecod/remainder-vs-modulus-3mc8</guid>
      <description>&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;Remainder and Modulo are two mathematic operations that are highly used in programming and computing in general. They both are represented by &lt;code&gt;%&lt;/code&gt;, but they act differently, their differences are usually overlooked, but they are really important as now knowing the differences between the both might cause production bugs in an application.&lt;/p&gt;

&lt;h2&gt;
  
  
  Overview
&lt;/h2&gt;

&lt;p&gt;Remainder and Modulo operations are a part of modular mathematics. Modular mathematics is usually used in clocks. The remainder is simply the number left after the division of two numbers, for example, &lt;code&gt;17 % 12&lt;/code&gt; would be &lt;code&gt;5&lt;/code&gt; as the number left after dividing 17 by 12 is 5. Its representation on a clock would look like this:&lt;br&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%2Fl4j3xszvhi6xlz0jnh5p.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%2Fl4j3xszvhi6xlz0jnh5p.png" alt="Clock 1" width="640" height="563"&gt;&lt;/a&gt;&lt;br&gt;
As shown in the diagram above, you first took a cyclic turn around the clock which accounted for dividing the dividend by the divisor 12. After a cyclic turn, you are left with 5 so you go forth 5 places, and 5 is the answer of &lt;code&gt;17 % 12&lt;/code&gt;. The Modulus operator would work the same way except that it would act differently when one of the operands is negative.&lt;/p&gt;

&lt;h2&gt;
  
  
  The Negative Number Game
&lt;/h2&gt;

&lt;p&gt;Remainder and Modulus operators work the same way until and unless they are operated upon negative operands. The remainder operator would operate the negative operands in the same way as it operates the positive operands, it would just not consider the negativity of the number. On the contrary, modulus would operate differently, and here's how.&lt;br&gt;
&lt;br&gt;&lt;br&gt;&lt;br&gt;
As proved earlier using clock math diagrams, &lt;code&gt;17 % 12&lt;/code&gt; would result in 5 as the remainder. &lt;code&gt;17 % -12&lt;/code&gt; would also result in the result being &lt;code&gt;5&lt;/code&gt; as after one oscillation around the clock, 5 would be the answer. What about &lt;code&gt;17 % -12&lt;/code&gt; using a modulo operator? We would need to use a different type of clock to depict the calculations.&lt;br&gt;
&lt;br&gt;&lt;br&gt;
So in modular mathematics, a clock hand's clockwise turn always increments the number of hours(value). So for carrying out &lt;code&gt;17 % -12&lt;/code&gt; we would need a clock that increments the negative number -12, and it would look like this:&lt;br&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%2F39aujeq7q9ql3bfgrb01.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%2F39aujeq7q9ql3bfgrb01.png" alt="Modulus clock representation" width="640" height="556"&gt;&lt;/a&gt;&lt;br&gt;
In the above figure, the clock is turning clockwise and the number is being incremented, so after a whole oscillation around the clock, we would have 5 left as the remainder, but we are using modulus so we will move the clock hand 5 steps further which results in the result being &lt;code&gt;-7&lt;/code&gt;.&lt;br&gt;
&lt;br&gt;&lt;br&gt;
The dividend could also be a negative number with the divisor being positive. You would similarly solve that. Suppose &lt;code&gt;-14 mod 12&lt;/code&gt;, so when we represent this on a graph, it would look like this:&lt;br&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%2Fxymt155quo6xeczrtso9.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%2Fxymt155quo6xeczrtso9.png" alt="Modulus negative dividend clock" width="640" height="586"&gt;&lt;/a&gt;&lt;br&gt;
In the above figure, we move the clock hand counterclockwise because the dividend is negative. After a single oscillation around the clock we just have 2 counter-clockwise clock hand turns left so the answer of this operation is &lt;code&gt;10&lt;/code&gt;, had the modulus been remainder in this operation, the answer would have been &lt;code&gt;2&lt;/code&gt;&lt;br&gt;
&lt;br&gt;&lt;br&gt;
In other words, the remainder operator returns the number of turns of the clock hand left after $n$ number of complete oscillations. The remainder is a result of modular division. The modulus operator returns the position of the clock hand after moving all the turns left. While using the modulus operator, we have to use all the clock hand turns left and then return the final clock hand position.&lt;br&gt;&lt;br&gt;
A point to be noted is that the clock is only shown because the divisor in all the operations is 12, you would not be able to represent an operation with some other remainder on a clock with 12 positions.&lt;/p&gt;

&lt;h2&gt;
  
  
  Which is Which
&lt;/h2&gt;

&lt;p&gt;You must be thinking about how to differentiate between the modulus and remainder operator, given that they have the same sign &lt;code&gt;%&lt;/code&gt; in code. The answer is: it depends. It depends on the programming language you are coding in. Different programming languages, consider the &lt;code&gt;%&lt;/code&gt; symbol differently. For example, JavaScript, C++, and C# consider &lt;code&gt;%&lt;/code&gt; as remainder operator whereas programming languages like Ruby consider &lt;code&gt;%&lt;/code&gt; as modulus.&lt;/p&gt;

&lt;h2&gt;
  
  
  Where can this knowledge be used
&lt;/h2&gt;

&lt;p&gt;Details are important. The details discussed above might make you think that they have no use, but yes they do! Knowing these details might help you with that production bug you just pushed or these details might be asked in a job interview.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Relational DBMS explained</title>
      <dc:creator>Hargunbeer Singh</dc:creator>
      <pubDate>Tue, 21 Sep 2021 13:09:01 +0000</pubDate>
      <link>https://dev.to/hamiecod/relational-dbms-explained-396d</link>
      <guid>https://dev.to/hamiecod/relational-dbms-explained-396d</guid>
      <description>&lt;p&gt;A relational database consists of rows and columns in a table, relational databases use SQL as their query language. They follow a relational data modeling paradigm. In a table, we need to uniquely identify each row, suppose it is a table of students in a university, you cannot uniquely identify a row based on the student's name as two students might have the same name, you cannot even uniquely identify a row based on the student's address as two students might be living at the same place, so you need to uniquely identify each student by a student ID that is unique to every student, this in the relational data modeling paradigm, is called the primary key, it is the key which uniquely identifies a row in a table.&lt;br&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%2Fxdguf00o7xuzifsfbh23.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%2Fxdguf00o7xuzifsfbh23.png" alt="Students Relational Table" width="411" height="361"&gt;&lt;/a&gt;&lt;br&gt;
In this university database analogy, you would have another table that would store the data for the classes. In the classes table, you also need a primary key that would uniquely identify each row in the table. The name of the class cannot act as the primary key as there could be two classes with the same name, likewise, the instructor cannot act as the primary key as an instructor might be teaching more than one class. So, here we would use the class id as the primary key to uniquely identify each class.&lt;br&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%2Fiwhhse647cokx35qo7tv.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%2Fiwhhse647cokx35qo7tv.png" alt="Classes Relational Table" width="411" height="341"&gt;&lt;/a&gt;&lt;br&gt;
We can use the relational data modeling scheme of the relational databases to connect the two tables by their primary keys into a single table which would contain only the primary keys of both the tables. For example, we need to create a table that would store the enrollments which are the classes a student is taking. In this scenario, we could just link the primary keys of both the tables in a single table like this:&lt;br&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%2Fl7r54yvw7m5lflk6p6lf.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%2Fl7r54yvw7m5lflk6p6lf.png" alt="Common relation table between the classes and students table" width="640" height="234"&gt;&lt;/a&gt;&lt;br&gt;
This can become complex when the number of rows of data increases so it is really difficult to scale. The new table that has been formed can be really useful as it provides us with the data about the attendees of a particular class as well as the data regarding the classes a student is taking. You can add another column to the new table formed by the merging of the primary keys of the two tables. For example, we can add a grade column to the newly formed table, and now we are having a lot of useful data in the newly formed table.&lt;br&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%2Fnrfltjg82l5dtkqvz4qe.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%2Fnrfltjg82l5dtkqvz4qe.png" alt="Grades table formed by the primary keys of two tables" width="640" height="217"&gt;&lt;/a&gt;&lt;br&gt;
Note that the student id, as well as the class id, do not act as primary keys in the ENROLLMENTS table, and thus the enrollments table does not have a primary key, so we would go ahead and add a primary key to the enrollments table. We would use Enrollment ID as the primary key as it can uniquely identify rows of data.&lt;br&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%2Fopfd5c7nlc8qcuj5411x.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%2Fopfd5c7nlc8qcuj5411x.png" alt="Enrollments table with primary key" width="640" height="199"&gt;&lt;/a&gt;&lt;br&gt;
The student ID is the primary key of a specific table and the class id is the primary key for a specific table. So, in the grades table, the student id is the foreign key for the students table and the class id is the foreign key for the classes table. A foreign key is a key in a table that is the primary key of another table's row. Foreign keys are really useful as you can use them to retrieve more data about a specific foreign key&lt;br&gt;
&lt;br&gt;&lt;br&gt;
For example, I am looking at the Grades table, and from there I get to know that the student with student ID 103 has only taken one class this semester, so I want to contact the student but the grades table does not have the student's address, but as the student id is a primary key of the students table, I would go on to look the students table with the primary key I found in the Grades table to fetch more information about the particular student, and there I would find student id 103's address. So the relationship between the students table and the grades table is one to many. The relationship between the Grades table and the classes table is many to one. A many to one relationship is a relationship between two tables, where many foreign keys relate to a single primary key in another table, like in this case, the same class ids in the grades table link to a single primary key in the classes table. The class ids in the grades table are the foreign keys for the classes table. &lt;br&gt;
&lt;br&gt;&lt;br&gt;
These types of relationships are formed to avoid redundant data in a database and also to avoid some other problems. As described earlier, by using foreign keys for a particular table, we can usually find more information about the particular foreign key. Foreign key relationships are possible due to the relational data modeling paradigms. What if we did not have a relation between the Grades and the Classes table and we had information about the Classes combined in the Grades table. &lt;br&gt;
&lt;br&gt;&lt;br&gt;
So, with relationship, we do not need to write all the data about a particular class in the grades table, but without a relationship, we have to write about the classes in the grades table, so a particular class id would have the same instructor and the same name which would result in redundant data. Redundant data is different as compared to duplicate data, duplicate data will have different primary keys whereas redundant data would have the same foreign key. Storing redundant data is a huge loss of space, and in this scenario, there would be hundreds of students taking the same class, thus we would have to write the instructor and the class name hundreds of times, wasting a lot of storage.&lt;br&gt;&lt;br&gt;&lt;/p&gt;

&lt;p&gt;The other problem with redundant data storage is that it causes a lot of problems with updating and retrieving data from the database. So we continue the previous example, suppose the instructor for a particular class changed, you will have to change the instructor name hundreds of times in the Grades table because the name of the previous instructor has been written there multiple times. After all, there is redundant data. There are databases with millions of rows of data and updating the data in millions of rows is fatal for the speed as the CPU would be millions of times slower in completing the task as compared to updating a single row of data where the relationship between tables exists. If you do not update each row of data in a table that has redundant data, it may cause a lot of problems with retrieving data from the database. &lt;br&gt;
&lt;br&gt;&lt;br&gt;
Suppose the instructor changed and you did not update every row with the new instructor name, so when somebody wants to send an email to the instructor of a particular course, he would perform a query to the database for the specific class instructor, what if the query returns the first result which is the old data which was not updated and contained the name of the old instructor rather than the new instructor, thus causing a discrepancy in the application of the database. To avoid all this, we use relationships between different tables. There are some limitations for lots of reading and write queries per second, this is due to the relations between data and because SQL enforces ACID requirements.&lt;/p&gt;

</description>
      <category>database</category>
      <category>dbms</category>
    </item>
    <item>
      <title>How YouTube optimizes video delivery</title>
      <dc:creator>Hargunbeer Singh</dc:creator>
      <pubDate>Tue, 21 Sep 2021 12:39:35 +0000</pubDate>
      <link>https://dev.to/hamiecod/how-youtube-optimizes-video-delivery-83i</link>
      <guid>https://dev.to/hamiecod/how-youtube-optimizes-video-delivery-83i</guid>
      <description>&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;YouTube is a massive video-sharing platform with billions of active users so YouTube needs to optimize everything on its platform. YouTube uses a lot of ways to optimize the performance of its apps. YouTube uses a lot of caching and has a very big network of servers over the planet. We will discuss how YouTube stores the videos and how it delivers the videos to its clients.&lt;/p&gt;

&lt;h2&gt;
  
  
  Overview
&lt;/h2&gt;

&lt;p&gt;YouTube has a lot of video quality options like you can watch the video at a lot of different resolutions like 144p, 320p, 480p, 720p, 1080p, 2k, and 4k. So when a video is uploaded on YouTube, YouTube makes a lot of copies of the video in a lot of different resolutions and stores it on their servers. So when a client asks for a particular resolution, YouTube responds with a particular copy of the video. A particular video on YouTube is available on a lot of databases located at different places on the planet. &lt;br&gt;
&lt;br&gt;&lt;br&gt;&lt;/p&gt;

&lt;p&gt;When a video is posted to YouTube from the USA, it is at first stored at the nearest server to the location it was uploaded from. When the same video is requested in Russia, YouTube requests the video from the USA servers and sends it to the requester from Russia. When the video reaches the Russian requester, a copy of the same video is stored on the Russian server so that it is quicker for the other Russian requesters to receive that video. YouTube might cache the video in the local area only if a certain amount of people request the video from that region. Receiving data from a far location consumes more time than receiving data from a near location, this is why YouTube caches the video in the local server/CDN.&lt;br&gt;
&lt;br&gt;&lt;br&gt;&lt;/p&gt;

&lt;p&gt;When a video is uploaded to YouTube, YouTube breaks the video apart into very short clips for a better delivery time of the video to the client. It responds to the client with short clips of the actual video, so that it takes less delivery time and also because YouTube could fetch short clips of the video in the background while the client was watching a certain clip of the video. YouTube doesn't need to fetch the clips in proper order, sometimes it fetches clips of the video out of order and then couples them together for the client when the client is watching the video.&lt;br&gt;&lt;br&gt;&lt;/p&gt;

&lt;p&gt;YouTube splits the video into the video graphics and the audio for content delivery optimization. A lot of people run YouTube in the background and are just hearing the audio of the video, this happens in a lot of cases like when you are listening to a podcast or music on YouTube. YouTube listens for this case and then just sends the audio to the client and does not send the video at all to the client, this saves YouTube a lot of bandwidth and also increases the speed of delivery of the content as just the audio is being sent which is a lot smaller in size than the audio and video combined.&lt;br&gt;&lt;br&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;


&lt;p&gt;YouTube has a crazily complex infrastructure and the fun fact is that when you post a video to YouTube, it will end in 100s of pieces and at lots of locations on the planet, so at last your video would have 1000s of copies on the YouTube servers. Other video streaming platforms like Netflix, Amazon Prime Video, Twitch, etc. use a similar technique for video streaming. The complexity of the infrastructure increases manifold as an app grows.&lt;br&gt;&lt;br&gt;
&lt;/p&gt;


</description>
      <category>performance</category>
      <category>webdev</category>
      <category>devops</category>
    </item>
    <item>
      <title>Programming languages are overrated!</title>
      <dc:creator>Hargunbeer Singh</dc:creator>
      <pubDate>Mon, 20 Sep 2021 01:31:12 +0000</pubDate>
      <link>https://dev.to/hamiecod/programming-languages-are-overrated-1aba</link>
      <guid>https://dev.to/hamiecod/programming-languages-are-overrated-1aba</guid>
      <description>&lt;p&gt;Edit: I posted a video about this topic &lt;a href="https://youtu.be/x0pDwekDcWM" rel="noopener noreferrer"&gt;here&lt;/a&gt; so you can go watch that if you do not like reading :)&lt;/p&gt;

&lt;p&gt;“Most People” go on to learn  to use programming languages and frameworks rather than learning the core concepts of how a particular platform (say the web) works. “They” do not go on to learn how code gets executed in a programming language they rather pay more attention to learn how to code.&lt;/p&gt;

&lt;p&gt;I’ll support my opinion with an analogy to convince you - if you teach a person how to catch fish using a spear, the person would catch the fish and use the fish for nutrition but if you teach a person how exactly a spear works, or in other words, teach them the craft to use any weapon, the person would be able to feed himself for his whole life; even if the fish disappear, the person would be able to hunt other animals for food. &lt;/p&gt;

&lt;p&gt;I'll also support my analogy with mathematics, as it is the only art that never lies, suppose a person takes 5 years' hard work to master the weapon craft and catches no fish what so ever in that time; on the contrary, a person who just knows how to "catch" fish would catch maybe 5 fish a day so the person would in total catch 9125 fish(5*365*5) in 5 years. &lt;/p&gt;

&lt;p&gt;When the person who is a master of the craft would start to catch fish, I am pretty sure that he would be able to catch 1000 fish in a day, so as basic math says, the person would be able to catch 10000 fish(10*1000) in 10 days. This proves that a person who masters the core craft would earn more in 10 days than the normal person earns in 5 years. Also, that talent stays for ever, so you can catch a 1000 fish or chicken or crabs for the rest of your life everyday.&lt;/p&gt;

&lt;p&gt;Such is programming you teach a person how to write a timer in JavaScript, he will be able to sell that timer code for some money once; but if you teach the person how does programming and problem solving work at its core, the person will be able to feed himself for life. What I wanted to express via this short article is that - don’t go after learning more and more “programming languages”, go after learning how a particular niche works IN DEPTH.&lt;/p&gt;

&lt;p&gt;If you know the concepts well you can easily implement the system design easily in code. As very less people learn these concepts, it is an opportunity for you to become one of the top programmers in a niche.&lt;/p&gt;

</description>
      <category>programming</category>
      <category>computerscience</category>
      <category>codenewbie</category>
    </item>
    <item>
      <title>Data Structures for Dummies</title>
      <dc:creator>Hargunbeer Singh</dc:creator>
      <pubDate>Wed, 08 Sep 2021 14:46:58 +0000</pubDate>
      <link>https://dev.to/hamiecod/data-structures-for-dummies-47ec</link>
      <guid>https://dev.to/hamiecod/data-structures-for-dummies-47ec</guid>
      <description>&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;A data structure is a way how data is stored in the memory, it is is really important to store your data in the correct data structure for optimal algorithmic performance. In technical words, a data structure is a data organization, management and storage format that enables efficient access and modification. It is an algebraic structure about data. Using a data structure, makes it easy to retrieve and read data from the memory. They are generally based on the ability of a computer to fetch and store data at any place in its memory. A simple example of a data structure is an array, it is used to store a series of values in memory. &lt;/p&gt;

&lt;h2&gt;
  
  
  Types of Data Structure
&lt;/h2&gt;

&lt;p&gt;Choosing the right data structure for performing a particular task is a choice that pays you off in the future. The use of right data structures make a computing task a lot more efficient and easy to code. There are a lot of data structures used for different types of tasks, some of the popular data structures are described below. &lt;/p&gt;

&lt;h3&gt;
  
  
  Array
&lt;/h3&gt;

&lt;p&gt;Arrays are a series of values stored in memory. One-dimensional arrays are the arrays which just have the values stored in a series in them and do not have other nested arrays inside them. One-dimensional arrays are also referred to as vectors. We can point to a value in an array using index, most programming languages start indexes with &lt;code&gt;0&lt;/code&gt;, for example we can reference the first value in an array called &lt;code&gt;hobbies&lt;/code&gt; by &lt;code&gt;hobbies[0]&lt;/code&gt;. An array is stored in memory in the following way: its consequent values are stored in the memory as corresponding data types, like an array containing 4 values would store the values as their corresponding data types in memory from lets say memory location 1000 to 1003, although they are stored as common data but still the compiler knows that all the values are a part of a single array. An array of values is fixed and cannot be enlarged to add more values. Arrays also need to be stored in order in memory which makes it hard to add a new value(*do not relate to pushing a value into an array)&lt;/p&gt;

&lt;h3&gt;
  
  
  Strings
&lt;/h3&gt;

&lt;p&gt;A string datatype is also stored as an array in memory, lets suppose the string &lt;code&gt;Hello World&lt;/code&gt;, the compiler would store the string by splitting it into individual characters, so &lt;code&gt;H&lt;/code&gt; would be stored in memory location &lt;code&gt;1ooo&lt;/code&gt; and the space would be stored in memory location &lt;code&gt;1005&lt;/code&gt; and so on, the compiler denotes the ending of the string by a null character, giving the compiler a signal that it needs to stop reading the data from the memory, and when the compiler fetches the data from the memory, it merges the individual characters and forms a string.&lt;/p&gt;

&lt;h3&gt;
  
  
  Matrix
&lt;/h3&gt;

&lt;p&gt;We can use arrays to make one-dimensional lists but sometimes we need multi-dimensional data structures to store data like the value of each pixel on a screen or the data stored in a spreadsheet, a multi-dimensional data structure is called a matrix. It is an array of arrays, so it contains a series of arrays which further contain a series of values. For example: A 3 by 3 matrix would be an array of 3 sub-arrays which are an array of 3 values each. They are stored in memory similar to how arrays are stored in memory. The values of sub-arrays of a matrix are stored as their corresponding data types in the memory and when the compiler reads them, it knows that they are the sub-arrays of a matrix. Matrices are not only limited to two or three dimensions, they can be of any dimensions, so a five dimensional matrix would have 5 layers of arrays, so you can point to a value in a five dimensional array like this &lt;code&gt;hobbies[3][5[8][4][5]&lt;/code&gt;, higher level matrices are used to store relatively complex and more nested data sets.&lt;br&gt;&lt;br&gt;&lt;br&gt;
&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fsvgshare.com%2Fi%2F_yh.svg" 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%2Fsvgshare.com%2Fi%2F_yh.svg" alt="Matrix Image" width="800" height="400"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Struct
&lt;/h3&gt;

&lt;p&gt;It is a great programming practice to store a set of related variables together, like you should store the data about an employee, like his age, salary and designation in a struct as all these variables are related, objects(as popularly called in programming languages) are a higher level implementation of structs. For example: you can retrieve the &lt;code&gt;age&lt;/code&gt; of an employee from the memory from the &lt;code&gt;employee&lt;/code&gt; struct by &lt;code&gt;employee.age&lt;/code&gt;. We can even make arrays of structs that we define, and structs are automatically bundled up in memory. So in an array of structs, we can retrieve a struct by pointing to its index in the array and then to retrieve a value from the specific struct we would point to the variable name. Structs can be used to make more complex data structures which avoid the problems with arrays, i.e. new values cannot be added in the middle of an array because they are stored in order in memory. These structures are called Nodes&lt;/p&gt;

&lt;h3&gt;
  
  
  Node and Linked List
&lt;/h3&gt;

&lt;p&gt;It is a type of struct that stores both the variable and a pointer in itself. A pointer is a special variable that points to a location in memory. Using node, we can create a linked list, which is a complex data structure which is flexible and stores many nodes. A linked list stores multiple nodes by pointing each node to the next node in the linked list. A linked list eliminates the problems of an array as it is very flexible in storing nodes, the nodes do not need to be stored in a particular order and two nodes can have other data between them. The pointer in each node comes into play in joining the linked list, so suppose we have a linked list with three nodes, the first node would point to the second node's location in memory and the second node will point to the third node's location in the memory, if the third node points back to the first node's location in memory, that means that the particular linked list is a circular linked list.&lt;br&gt;
&lt;br&gt;&lt;br&gt;&lt;br&gt;
&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fsvgshare.com%2Fi%2F_z6.svg" 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%2Fsvgshare.com%2Fi%2F_z6.svg" alt="Linked List Diagram" width="800" height="400"&gt;&lt;/a&gt;&lt;br&gt;
&lt;br&gt;&lt;br&gt;
If the value of the pointer of the last node is null, then the linked list ends there. We can insert new nodes in the middle of the linked list, unlike arrays, as we just need to change the pointer value of the previous node while adding another node. Developers do not need to worry about the pointer values, that is work for the compiler and the developer can just visualize linked list by a layer of abstraction. Linked lists, due to their flexibility, can also be easily re-ordered, trimmed, split, reversed, etc. Linked lists are really useful for algorithms like sorting algorithms. Because of the flexibility that Linked Lists offer, many more data structures are build on top of linked lasts, the most famous ones are queues and stacks.&lt;/p&gt;

&lt;h3&gt;
  
  
  Queues
&lt;/h3&gt;

&lt;p&gt;A queue is a data structure that follows a first-in first-out(FIFO) approach. As its name states, FIFO is an approach where the first arriver is served first. It is built upon linked lists. Suppose in a linked list, we have a pointer that points to a bank queue visualized like this:&lt;br&gt;
&lt;br&gt;&lt;br&gt;&lt;br&gt;
&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fsvgshare.com%2Fi%2F_yg.svg" 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%2Fsvgshare.com%2Fi%2F_yg.svg" alt="Bank Queue Example Data Structure" width="800" height="400"&gt;&lt;/a&gt;&lt;br&gt;
&lt;br&gt;&lt;br&gt;&lt;br&gt;
So the bank queue is a queue data structure where Steve points to Michael, Michael points to Anna and Anna points to Della, Della is the last node in the list as its pointer value is null. So after we have served Steve, we would read Steve's next pointer and dequeue Steve from the queue. To add a new node to the linked list, we would have to traverse down the linked list until we reach the node with pointer value null, and then we add the new node to the end of the linked list and update the pointer values of the former last node of the linked list. Adding a node to the queue is also called enqueueing.&lt;/p&gt;

&lt;h3&gt;
  
  
  Stacks
&lt;/h3&gt;

&lt;p&gt;Stacks are data structures build upon linked lists. They follow a Last-in First-out(LIFO) approach. As its name states, LIFO is an approach where the last arriver is served the first, and the first arriver is served the last. An analogy to explain that can be a pile of papers, so the paper that has been piled the last would be picked up the first, and the paper that was piled up the first would be picked up the last. Adding nodes to the stack is called pushing data to the stack. Removing data from the stack is called popping data from the stack.&lt;/p&gt;

&lt;h3&gt;
  
  
  Trees
&lt;/h3&gt;

&lt;p&gt;Trees are data structures built on linked lists; a tree data structure is just a node with multiple pointers. This data structure is used in the implementation of a lot of algorithms. Programmers generally do not consider looking at and evaluating the list of pointers and rather use a layer of abstraction to conceptualize trees like this:&lt;br&gt;
&lt;br&gt;&lt;br&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%2F53cfwsux8xs7w6o8jslt.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%2F53cfwsux8xs7w6o8jslt.png" alt="Tree Data Structure" width="420" height="314"&gt;&lt;/a&gt;&lt;br&gt;
&lt;br&gt;&lt;br&gt;
The top most node of the tree is called the "Root". Children nodes are the nodes a particular node points to. A parent node is a node which points to other nodes(children nodes). The nodes which do not have any children nodes in a tree data structure, they are called the leaf nodes. A tree data structure whose nodes can have maximum two children nodes are called binary trees. Their is only one way roots are connected to leaves and there cannot be a tree in which the roots link to leaves and the leaves link to roots.&lt;/p&gt;

&lt;h3&gt;
  
  
  Graph
&lt;/h3&gt;

&lt;p&gt;Graphs are used to store data that links arbitrarily. This type of data usually uses loops. A branch of mathematics - Graph Theory studies the graph data in detail. A graph is a data structure in which nodes are pointed to each other. In graph data structure too, the programmer doesn't need to care about the pointer values of various nodes; the programmer can usually visualize the graph with a level of abstraction as:&lt;br&gt;
&lt;br&gt;&lt;br&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%2Fwzthncs66szwzlca77ro.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%2Fwzthncs66szwzlca77ro.jpg" alt="Graph Data structure example" width="400" height="291"&gt;&lt;/a&gt;&lt;br&gt;
&lt;br&gt;&lt;br&gt;
The above image is a real life example of graph data, it represents all the paths a soldier can take to reach a particular place(node). Graph theory studies the paths(node pointers) and finds statistical data from the graph to find efficient techniques to perform various functions. Dijkstra's algorithm is a vital part of graph theory and it is an algorithm to find the shortest paths between nodes in a graph, in this case the shortest distance to reach a particular place. Graphs, other than computer science, are also used in real world scenarios, like finding the shortest distance between two cities or finding the shortest path to attack an enemy trench in a war.&lt;/p&gt;

&lt;h3&gt;
  
  
  Others
&lt;/h3&gt;

&lt;p&gt;These are the most popular common data structures, on top of these data structures, programmers have build more data structures with specific functionalities like red-black trees and heaps.&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;You must use data structures for writing efficient code and algorithms. Programmers do not need to implement these data structures from scratch as most programming languages have default packages which have implementations for common data structures.&lt;/p&gt;

</description>
      <category>datascience</category>
      <category>algorithms</category>
    </item>
    <item>
      <title>Cryptographic frequency Analysis explained</title>
      <dc:creator>Hargunbeer Singh</dc:creator>
      <pubDate>Tue, 07 Sep 2021 07:19:06 +0000</pubDate>
      <link>https://dev.to/hamiecod/cryptographic-frequency-analysis-explained-520a</link>
      <guid>https://dev.to/hamiecod/cryptographic-frequency-analysis-explained-520a</guid>
      <description>&lt;p&gt;Frequency Analysis is the study of frequency of letters or group or letters in a ciphertext. This method is relatively older to the newer methods of cryptanalysis. This method is used to break classic ciphers, this method is really useful in breaking substitution ciphers. It is based on the fact that certain letters or group of letters in a specific language text occur with specific frequencies. There is a distribution of the frequencies of letters that occur in a particular language. For example: the letters &lt;code&gt;E&lt;/code&gt;,&lt;code&gt;A&lt;/code&gt;,&lt;code&gt;T&lt;/code&gt; and &lt;code&gt;O&lt;/code&gt; occur the most in a piece of text in the English language. Similarly, the letter pairs - &lt;code&gt;TH&lt;/code&gt;, &lt;code&gt;ER&lt;/code&gt;, &lt;code&gt;ON&lt;/code&gt; and &lt;code&gt;AN&lt;/code&gt; are the most common in a piece of text in the English language, these pairs are reffered to as bigrams.&lt;br&gt;&lt;br&gt;&lt;/p&gt;

&lt;p&gt;In some ciphers, the properties and patters of the plaintext is preserved in the ciphertext, and these patterns can easily be studied and then the cipher can be exploited. The ciphertext usually retains the properties of the plaintext when a single letter always gets encrypted to the same ciphertext letter, this usually occurs in substitution ciphers. This type of attack is called ciphertext-only attack. Ciphertext-only attack is the attack in which the cryptanalyst just has the access to the ciphertext and nothing else. The cryptanalyst, in some cases might also know the language of the plaintext, where the cryptanalyst can use techniques like frequency analysis and index of coincidence.&lt;br&gt;&lt;br&gt;&lt;/p&gt;

&lt;p&gt;When a plaintext is encrypted using a substition cipher, and the cryptanalyst know the actual language of the plaintext, the cryptanalys can easily find frequency distribution and sequences in the ciphertext in most cases. For example: if a ciphertext contains a high frequency of &lt;code&gt;R&lt;/code&gt; in it and the plaintext language was English, the cryptanalyst would know that &lt;code&gt;R&lt;/code&gt; would most probably be &lt;code&gt;E&lt;/code&gt;, &lt;code&gt;T&lt;/code&gt; or &lt;code&gt;A&lt;/code&gt; in the plaintext as these letters occur the most in English, he would still need to try more combinations but frequency distributions make the combinations to try a lot lesser.&lt;/p&gt;

</description>
      <category>cryptography</category>
      <category>security</category>
      <category>devops</category>
    </item>
    <item>
      <title>Cryptography explained</title>
      <dc:creator>Hargunbeer Singh</dc:creator>
      <pubDate>Tue, 07 Sep 2021 06:18:31 +0000</pubDate>
      <link>https://dev.to/hamiecod/cryptography-explained-27ph</link>
      <guid>https://dev.to/hamiecod/cryptography-explained-27ph</guid>
      <description>&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;Cryptography is the study and practice of techniques used for secure communication in the presence of adversarial behavior. An Adversary is a malicious entity that does not want the users of a specific cryptosystem to communicate and achieve their goal. The adversary might try to corrupt the data or retrieve the information in the data. &lt;br&gt;&lt;br&gt;&lt;/p&gt;

&lt;p&gt;Cryptography is about constructing and analyzing ways and protocols that prevent third parties from reading private data while it is transmitted to the desired receiver. The pillars of cryptography are confidentiality, data integrity, authentication and non-repudiation(highly used principle in blockchain). Ciphers, Encryption and Cryptographic hash functions form a huge part of cryptography. Cryptography is based on the disciplines of mathematics, computer science and physics. Cryptography is highly used in, sending emails and messages, secure credit card transactions, cryptocurrencies, blockchains, storing data and and military communications.&lt;br&gt;&lt;br&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Overview
&lt;/h2&gt;

&lt;p&gt;Encryption is a modern day implementation of cryptography, It is the technique of converting readable information into something completely unreadable, such that only authorized parties can convert the unreadable information back into readable information, thus increasing communication security. This is made possible as the algorithm to decode the unreadable pseudorandom text is only shared in-between the authorized parties. Since the development of cryptographic machines like the enigma and Lorenz cipher machine in the world wars, cryptographic techniques have advanced manifold as its use cases have also increased. Cryptography is used everywhere, the messages sent via social media apps are also encrypted so that no hacker in between can intercept the messages. Cryptography, over several years, has become more term of computer science than mathematics as it is used a lot in computers. Modern cryptography is heavily based on mathematical theory and computer science practice, cryptographic algorithms are designed around computational hardness assumptions which states that an algorithm cannot be broken efficiently(in context to time). Well designed cryptographic algorithms cannot be broken in most cases, and the only way to break a cryptographic algorithm is bruteforce, which is a trial and error method of finding out what the encrypted data is, in the case of bruteforce, it depends on the amount of computational resources allocated to breaking the algorithm. There are some cryptographic algorithms which cannot be broken even by bruteforce, like OTP(one time pad).&lt;/p&gt;

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

&lt;p&gt;In cryptographic literature, the names "Alice", "Bob" and "Eve" are frequently used. "Alice" is the sender and "Bob" is the receiver, whereas "Eve"(eavesdropper) is an adversary. You can assume names in cryptographic literature according to a specific scheme. You have to name the entities in alphabetical order, like first a name starting with "A", then "B","C","D" and so on, but you skip the name with "E" as a common entity because it is the adversary. For example: &lt;strong&gt;A&lt;/strong&gt;lice, &lt;strong&gt;B&lt;/strong&gt;ob, &lt;strong&gt;C&lt;/strong&gt;harlie, &lt;strong&gt;D&lt;/strong&gt;arwin, &lt;strong&gt;F&lt;/strong&gt;inn and so on.&lt;br&gt;&lt;br&gt;
&lt;strong&gt;Cryptography&lt;/strong&gt; is the practice of cryptographic techniques whereas &lt;strong&gt;cryptology&lt;/strong&gt; is the study of both cryptography and cryptanalysis. &lt;strong&gt;Cryptolinguistics&lt;/strong&gt; is the study of characteristics of languages that have some application in cryptography or cryptology. For example: frequency data, letter combinations(linguistics), patters, etc.&lt;/p&gt;

&lt;h2&gt;
  
  
  Disciplines
&lt;/h2&gt;

&lt;p&gt;There are a lot of disciplines under cryptographic, there is assymetric key encryption, symmetric key encryption, substitution cipher and a lot more.&lt;/p&gt;

&lt;h3&gt;
  
  
  Read More
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Cryptographic Hash functions&lt;/li&gt;
&lt;li&gt;Cipher&lt;/li&gt;
&lt;li&gt;ciphertext&lt;/li&gt;
&lt;li&gt;codetext&lt;/li&gt;
&lt;li&gt;cryptanalysis&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>webdev</category>
      <category>devops</category>
    </item>
    <item>
      <title>Clickjacking explained</title>
      <dc:creator>Hargunbeer Singh</dc:creator>
      <pubDate>Sat, 04 Sep 2021 14:25:33 +0000</pubDate>
      <link>https://dev.to/hamiecod/clickjacking-explained-4fd3</link>
      <guid>https://dev.to/hamiecod/clickjacking-explained-4fd3</guid>
      <description>&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;Clickjacking, also referred to as UI redressing, is a malicious technique of tricking a user into clicking something different from what the user actually perceives. The user clicks on seemingly harmless objects, but actually they are a trap and are something completely different. Using clickjacking, sensitive information of the victim can be exposed, also the attacker can take control over your computer. The attacker redresses the malicious UI into something completely different that looks harmless, that is why clickjacking is also referred to as "UI Redressing"&lt;br&gt;&lt;br&gt;&lt;/p&gt;

&lt;p&gt;Clickjacking is an instance of the confused deputy problem in which the user is tricked into thinking that a malicious object is harmless, by disguising the malicious object. The users are then tricked and made to click the malicious objects that trigger malicious actions. Their is a privilege escalation of the attacker when the victim clicks the malicious object. Clickjacking is used for a plethora of web attacks, like CSRF. Clickjacking is performed on the attacker-maintained website, so a clickjacker can only harm a user and not a server.&lt;/p&gt;

&lt;h2&gt;
  
  
  Example
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;The attacker could disguise a money transfer form into something else, and when the user enters his data, the money transfer would occur, thus causing the victim a loss.&lt;/li&gt;
&lt;li&gt;The attacker could disguise a malicious ad link as the play button on a video and direct you to an ad.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Categories
&lt;/h2&gt;

&lt;p&gt;Clickjacking has a lot of categories which are as follows:&lt;/p&gt;

&lt;h3&gt;
  
  
  Classic
&lt;/h3&gt;

&lt;p&gt;Classic clickjacking is a situation when an attacker uses hidden layers on web pages to manipulate the actions of the user's cursor, resulting in the clicking of a malicious element.&lt;/p&gt;

&lt;h3&gt;
  
  
  Likejacking
&lt;/h3&gt;

&lt;p&gt;Likejacking is a malicious technique of tricking victims viewing a website to like a post on a website, which they really didn't intend to like.&lt;/p&gt;

&lt;h3&gt;
  
  
  Nested
&lt;/h3&gt;

&lt;p&gt;Nested clickjacking works by embedding a malicious web frame between two frames of the original, harmless web page - which is the framed page and the page which is displayed on the top window. Nested clickjacking works due to a vulnerability in the &lt;code&gt;X-Frame-Options&lt;/code&gt; HTTP header. When the &lt;code&gt;X-Frame-Options&lt;/code&gt; header has the value &lt;code&gt;SAMEORIGIN&lt;/code&gt;, the web browser checks the two layers which are harmless and does not check the malicious layer in between, thus enabling the attackers to exploit the vulnerability.&lt;/p&gt;

&lt;h3&gt;
  
  
  Cursorjacking
&lt;/h3&gt;

&lt;p&gt;CursorJacking is a type of UI Redressing which makes the user perceive that the cursor is at some other location than its original location. The attacker hides the actual mouse cursor on his website and makes a cursor on the website which looks like the original cursor.&lt;/p&gt;

&lt;h3&gt;
  
  
  MouseJack
&lt;/h3&gt;

&lt;p&gt;MouseJack is a wireless hardware-based vulnerability which allows the attacker's keyboard input to be injected into vulnerable dongles.&lt;/p&gt;

&lt;h3&gt;
  
  
  Browserless
&lt;/h3&gt;

&lt;p&gt;Browserless clickjacking is a technique to replicate classic clickjacking in programs which do not run in a web browser. Browserless clickjacking is prevalent among Android devices, especially due to the way pop-up notifications work. The pop-up notifications have a small delay in between the moment the notification is requested and the moment the notification is actually displays on-screen. The attackers use this small delay to create a dummy button that lies underneath the actual notification, and it can be clicked upon.&lt;/p&gt;

&lt;h3&gt;
  
  
  CookieJacking
&lt;/h3&gt;

&lt;p&gt;CookieJacking is a form of clickjacking in which cookies are stolen from the victim's web browser. This is performed by tricking the user into performing a task on the malicious website(usually dragging an element) which perceives to be harmless. When the user performs the action, the user unknowingly is selecting the cookie content and sending it to the attacker. The attacker can then perform a CSRF attack and impersonate the user on the website.&lt;/p&gt;

&lt;h3&gt;
  
  
  FileJacking
&lt;/h3&gt;

&lt;p&gt;FileJacking is a technique using which the attackers use the web browser's capability to navigate through the computer and access the computer files in order to acquire personal data. This is performed by tricking the user into establishing an active file server through the file and folder selection window that browsers use. With this, attackers access and take files and personal information from their victim's computers.&lt;/p&gt;

&lt;h3&gt;
  
  
  Password manager attack
&lt;/h3&gt;

&lt;p&gt;Password manager attack is an attack in which some password managers insecurely autofill passwords for the http version of https-saved passwords, these password managers also sometimes fill in the data in iFrames. Most password managers do not protect against iFrame and redirection-based attacks and exposed additional passwords where password sync had been used on multiple devices. Browsers are safe and do not autofill data, like password managers do. Browsers do not autofill data if the protocol on the current login page is different from the protocol at the time the password was saved. Browsers also don't autofill data in iFrames.&lt;/p&gt;

&lt;h2&gt;
  
  
  Preventive Measures
&lt;/h2&gt;

&lt;p&gt;There are both client-side as well as server-side measures to prevent clickjacking.&lt;/p&gt;

&lt;h3&gt;
  
  
  Client-Side
&lt;/h3&gt;

&lt;p&gt;Clickjacking can be reduced on the client side by installing some plugins in browsers like NoScript, NoClickJack and GuardedID.&lt;/p&gt;

&lt;h3&gt;
  
  
  Sever-side
&lt;/h3&gt;

&lt;p&gt;There are various server-side ways to protect your users from clickjacking on your website.&lt;/p&gt;

&lt;h4&gt;
  
  
  Framekiller
&lt;/h4&gt;

&lt;p&gt;You can protect your users from UI redressing(frame based clickjacking) on the server side by including a framekiller JavaScript snippet in those pages which you do not want to be included inside frames on different websites. This type of protection against clickjacking is not very reliable, particularly on IE, where this kind of measure can be circumvented by including the targeted page inside an &lt;code&gt;&amp;lt;iframe security=restricted&amp;gt;&lt;/code&gt; element. This is a design issue in IE.&lt;/p&gt;

&lt;h4&gt;
  
  
  X-Frame-Options
&lt;/h4&gt;

&lt;p&gt;&lt;code&gt;X-Frame-Options&lt;/code&gt; is a HTTP header that can be used to indicate whether or not a particular website should be allowed to render a page in an iFrame, etc. Websites can use this to avoid clickjacking attacks as it ensures that a website's content is not embedded into other sites. &lt;code&gt;X-Frame-Options&lt;/code&gt; provide only partial security against clickjacking because the header will only be in effect if the user's browser supports it. You can allow certain website to embed your webpage on their website by specifying it, you can also allow the same origin web pages to embed a web page.&lt;/p&gt;

&lt;h4&gt;
  
  
  Content-Security-Policy
&lt;/h4&gt;


&lt;p&gt;The &lt;code&gt;frame-ancestors&lt;/code&gt; directive of the HTTP CSP(Content-Security-Policy) specifies valid elements that are allowed to embed a page using iFrames etc. This is similar to the &lt;code&gt;X-Frame-Options&lt;/code&gt; and its values are also similar to the values of &lt;code&gt;X-Frame-Options&lt;/code&gt;. The only difference is that &lt;code&gt;X-Frame-Options&lt;/code&gt; header just checks top-level document location that is the website URL whereas the &lt;code&gt;frame-ancestors&lt;/code&gt; directive checks each ancestor(parent), if the ancestor does not match with what is defined in the CSP, the load of the frame is cancelled. Also the CSP obsoletes(out fashions) X-Frame-Options header, if both the directives are specified on a web page, CSP is given the priority and the &lt;code&gt;X-Frame-Options&lt;/code&gt; header is ignored.&lt;br&gt;&lt;br&gt;
&lt;/p&gt;


&lt;h3&gt;
  
  
  Links
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://www.w3.org/TR/CSP2/#frame-ancestors" rel="noopener noreferrer"&gt;W3 implementation of Content-Service-Policy&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>security</category>
      <category>webdev</category>
    </item>
    <item>
      <title>Cross Site Request Forgery Explained</title>
      <dc:creator>Hargunbeer Singh</dc:creator>
      <pubDate>Fri, 03 Sep 2021 13:12:40 +0000</pubDate>
      <link>https://dev.to/hamiecod/cross-site-request-forgery-explained-1gjd</link>
      <guid>https://dev.to/hamiecod/cross-site-request-forgery-explained-1gjd</guid>
      <description>&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;CSRF stands for &lt;strong&gt;C&lt;/strong&gt;ross &lt;strong&gt;S&lt;/strong&gt;ite &lt;strong&gt;R&lt;/strong&gt;equest &lt;strong&gt;F&lt;/strong&gt;orgery. It is an attack in which the attacker pretends to be an authenticated user on a website and sends unwanted requests to the website, and the website backend thinks that the authenticated user is making the request. This can be done in many ways. The attacker could steal the cookie of the authenticated user and pretend to be the user on a specific website and perform any malicious requests to the website, like transferring money, deleting an account, etc. Another way to perform CSRF is to maliciously include malicious parameters in a link from a website to the victim website. A website is vulnerable to CSRF if it authenticates the user using GET requests. A malicious website could also have disguised a form which performs CSRF.&lt;/p&gt;

&lt;h2&gt;
  
  
  Overview
&lt;/h2&gt;

&lt;p&gt;The web works by sending data to and fro. Their are mainly two ways of sending data: GET and POST request. When you use GET request, the data which is sent as a parameter which is visible in the website address. GET requests are used to fetch data from a server. When using POST request, the data is sent to the server, but it is not visible in the website address. POST requests are used to send data to the server. Example: if you are watching a youtube video, the link would be like &lt;code&gt;youtube.com/watch?v=videoID&lt;/code&gt;, here the video id is a GET request parameter, and if you copy paste the link and send it to a friend, when she clicks on it, she would also get the same page. Whereas in POST request, when you post a comment, it is not visible in the search bar address, so even if you copy paste the link and send it to a friend, she would not post the same comment by clicking on that link, unlike she got the same page as you in the case of GET request. &lt;br&gt;&lt;br&gt;&lt;/p&gt;

&lt;p&gt;To perform CSRF, the attacker has to authenticate the user on the website via his malicious webiste, that can be done by making certain requests to a particular website in the background. Using GET requests, the attacker can perform CSRF by sending the data in parameters to the website to authenticate the user. When using POST request, the attacker sends the data to a website unnoticed by the user. GET requests are a boon to an attacker as the victim just needs to click the link and CSRF would be performed, this is why websites do not authenticate or perform important actions by storing data in the link parameters.&lt;/p&gt;

&lt;h2&gt;
  
  
  Examples
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;For example: You could hide a tweet form on your malicious website, so when the user clicks a button to post a comment, the event is triggered to tweet the data in the hidden form instead of posting the comment. The attacker authenticates you to twitter in the background using web workers and then sends the POST request to the twitter API to tweet the content from your account, and the tweet might be controversial, and that can cause trouble if you have a great following. The attacker can also make you transfer a million dollars from your account to his account using CSRF.&lt;/li&gt;
&lt;li&gt;A malicious website could also have disguised a form, for example: a money transfer form could have been disguised as a credit card linking form, where the amount field is hidden, and when you authenticate your credit card, and click the submit button, the POST request will go to the bank API instead of going to the malicious website API, thus performing the money transfer from your bank account. You would be authenticated to your bank in another tab or in the background.
&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%2Ffsoqf9l7fo149syuir28.png" alt="Diagram showinig how CSRF is used" width="800" height="472"&gt;
&lt;/li&gt;
&lt;li&gt;When you post a comment on a malicious website, the website might impersonate you on another website in the background or in another tab, and could do anything on that website by a POST request, like deleting your account.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Preventive Measures
&lt;/h2&gt;

&lt;h3&gt;
  
  
  'Referrer' Header
&lt;/h3&gt;

&lt;p&gt;Preventive measures against CSRF were introduced in the HTTP protocol. The preventive measure was to include a &lt;code&gt;Referrer&lt;/code&gt; header in the HTTP request, so that the API knows from which website is the HTTP request coming from. But that preventive measure did very less impact to CSRF because most of the users have ad blockers or privacy plugins which just do not allow them to send the &lt;code&gt;Referrer&lt;/code&gt; header to the API.&lt;/p&gt;

&lt;h3&gt;
  
  
  One-time key
&lt;/h3&gt;

&lt;p&gt;Another preventive measures against CSRF is a one-time key, which a lot of websites use these days. One-time key is also called the &lt;strong&gt;nonce&lt;/strong&gt;. Web apps use one-time key to authenticate POST requests or any commands that will have a permanent effect on the user. One-time key is near impossible to break, as it is something completely random, and the attacker cannot authenticate to the website without the nonce. The nonce is sent to the user using authentication apps like Google authenticator or via SMS on the user's phone number. Brute force can also not break one-time key because one-time keys are generally valid for a short period of time.&lt;/p&gt;

&lt;h3&gt;
  
  
  Same-Origin Policy
&lt;/h3&gt;

&lt;p&gt;The Same-Origin Policy forms a great part of the browser's security policy. Same-origin policy states that data on a particular api on a specific domain can only be accessed by requests from the same domain. This forms the barrier against CSRF, as the requests from other websites won't be able to impersonate the victim on another site. The website web servers should only allow their own domain to make HTTP requests for executing certain commands on the website on the web server.&lt;/p&gt;

&lt;h3&gt;
  
  
  Synchronizer token pattern
&lt;/h3&gt;

&lt;p&gt;Synchronizer token pattern is also referred to as CSRF token. It is a technique in which the server generates unique and random tokens to authenticate its users' requests. It needs to be unique for each POST request. CSRF tokens should be such that they are only accessible to a specific website. Due to CSRF tokens, the attacker is unable to make POST requests from a malicious origin as the attacker would not have the user's CSRF token. This is made possible due to Same-origin policy. Though, it is not mandatory that CSRF token need to be unique for each request, but the CSRF tokens should only be valid for a short period of time, preventing the attacker to brute force. The CSRF tokens must be declared invalid when a user session expires, because if you do not make the CSRF tokens invalid, the attacker could brute force the token, and then use it to exploit the user again in consequent sessions.&lt;/p&gt;

&lt;h2&gt;
  
  
  CSRF Phishing attack
&lt;/h2&gt;

&lt;p&gt;A common type of CSRF attack would take place like this:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;The attacker creates a new account on a website.&lt;/li&gt;
&lt;li&gt;The attacker makes the new account prone to Self-XSS on the website.&lt;/li&gt;
&lt;li&gt;The attacker leads the victim to a phishing site, which logouts the victim out of the website on which the CSRF is being performed.&lt;/li&gt;
&lt;li&gt;The victim is logged in to the CSRF-prone website with the attacker-created account. The victim is logged in, as the attacker tricks the victim to click a button on the phishing site which leads to the CSRF-prone website.&lt;/li&gt;
&lt;li&gt;Self-XSS is executed in the attacker-created account on the victim's computer which cleverly asks the victim to input his password&lt;/li&gt;
&lt;li&gt;The password is sent to the attacker&lt;/li&gt;
&lt;li&gt;The attacker authenticates the user to the website using the credentials entered, so that the user thinks that nothing has happened.&lt;/li&gt;
&lt;/ol&gt;

</description>
      <category>webdev</category>
      <category>security</category>
      <category>devops</category>
    </item>
    <item>
      <title>🍪Cookies and Cookie Tracking Explained</title>
      <dc:creator>Hargunbeer Singh</dc:creator>
      <pubDate>Mon, 30 Aug 2021 12:28:51 +0000</pubDate>
      <link>https://dev.to/hamiecod/cookies-and-cookie-tracking-explained-11co</link>
      <guid>https://dev.to/hamiecod/cookies-and-cookie-tracking-explained-11co</guid>
      <description>&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;A cookie is a small piece of information stored in the client's computer by a particular website via a web browser. They are used to personalize a user's experience on the particular website. It usually contains the user's preferences and inputs. A user can customize their web browser to accept, reject or delete cookies. Cookies can be modified at the server level by using the &lt;code&gt;Set-Cookie&lt;/code&gt; HTTP header. It can be modified at the client level by using &lt;code&gt;document.cookie&lt;/code&gt; in JavaScript.&lt;br&gt;&lt;br&gt;&lt;br&gt;
Cookies are shared to the server on consequent HTTP request. When you perform a HTTP GET request, the server returns you the webpage(HTML, CSS and JavaScript) along with some cookies which would be populated with data as you surf the specific web page. When you form another HTTP request to the server, the cookies which were populated with your data(preferences) are sent to the server. Thats how cookies help in storing the user's preferences. Cookies transactions take place between the user and the server using the &lt;code&gt;Set-Cookie&lt;/code&gt; header.&lt;br&gt;&lt;br&gt;&lt;br&gt;
There are two types of cookies - First Party Cookies and Third Party Cookies. First Party cookies, as the name says, are the cookies used by the website you are surfing to improve user experience. Third Party cookies are the cookies which are used by third-party services to improve the user experience, these are mostly advert companies, which improve user experience, like Google Ads which suggests you proper websites in its search ranking.&lt;br&gt;&lt;br&gt;&lt;br&gt;
Cookies are not stored as code on the user's machine, it is rather stored as simple files, which cannot be executed. Stored cookies cannot even manipulate the elements of your screen, it can't even access your mic or webcam. The only worry about cookies is thier system of allowing data(preferences) to be sent to the server without anybody noticing.&lt;/p&gt;

&lt;h2&gt;
  
  
  Examples
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;When you turn on the dark mode on YouTube, it would be stored in the cookies and would be sent back via a POST request as soon as you change the color mode. After that when you perform a consequent GET request to the YouTube server, it would return you the YouTube web page and the cookies populated with your preferences, this improves user experience as the user does not need to change the color mode on consequent visits to the particular website.&lt;/li&gt;
&lt;li&gt;When you log into a website on a device, an encrypted unique token is stored in the cookie which keeps you logged in the website everytime you open the website.&lt;/li&gt;
&lt;li&gt;Cookies are used to store the items in the shopping cart in an ecommerce website, they improve user experience as when you visit the website consequent times, you would not need to re-fill your cart with the items you had selected in the last session.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Web Security
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;You(as a developer) should never store sensitive information, like login information, in cookies as a hacker can perform XSS attacks or Session hijacking at1tacks to retrieve the cookies, which would cause loss of privacy of the sensitive information.&lt;/li&gt;
&lt;li&gt;If a hacker steals your cookie on a specific website via some attack(like XSS), the attacked can use your cookie to pretend to be you on that specific website and he might do harm to your privacy.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Cookie Tracking
&lt;/h2&gt;

&lt;p&gt;Cookie tracking is performed by third-party cookies usually, tracking cookies are used by third-parties to monitor the user's Web surfing habits and use the data for marketing purposes, like Google and Facebook ads. These types of cookies are generally considered as an invasion of privacy. When third-party ads are placed on a website, the third-party ad providers are also storing the user's data in cookies and then using the data for marketing and advertising purposes. For example: Big Tech giants, like google and facebook, store your data via cookies through ads as you surf the internet and then use that data to show you related advertisments, thus increasing their profits. Because of t4e privacy invasion of the users due to cookies, the EU(European Union) introduced the cookie law. The cookie law states that the websites need to ask for the user's permission to use cookies and give them a chance to opt out, thats why most of the websites ask for the user's permission before storing cookies.&lt;br&gt;&lt;br&gt;&lt;br&gt;
In very rare cases, some ads might also access your camera if you allow to, or access it directly if you have allowed the main website to access your webcam. The advertising companies would then capture your facial expressions while watching a video add and determine whether you were happy or sad while watching it and then use the data for marketing. This can happen in very rare cases, research on this type of technology is being done at MIT Media Labs.&lt;/p&gt;

&lt;h2&gt;
  
  
  Personal Opinion
&lt;/h2&gt;

&lt;p&gt;Users should be given the right to opt in for first-party cookies and just opt out for the third-party ones, but this gets very complex(from a developer perspective) and also it is very difficult to present to the user.&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>devops</category>
      <category>security</category>
    </item>
    <item>
      <title>Cryptanalysis- the study of breaking cryptosystems explained</title>
      <dc:creator>Hargunbeer Singh</dc:creator>
      <pubDate>Sat, 28 Aug 2021 12:32:42 +0000</pubDate>
      <link>https://dev.to/hamiecod/cryptanalysis-the-study-of-breaking-cryptosystems-explained-1p28</link>
      <guid>https://dev.to/hamiecod/cryptanalysis-the-study-of-breaking-cryptosystems-explained-1p28</guid>
      <description>&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;Cryptanalysis is a branch of cryptography that deals studies how to break codes and cryptosystems. It creates techniques to break the ciphers, the techniques are a lot more advanced than a simple brute force attack. Modern methods to break ciphers include linear cryptanalysis and differentil cryptanalysis, which are a lot more advanced than the traditional methods of breaking ciphers, like frequency analysis and index of coincidence. Cryptanalysis also includes exploiting weaknesses in the implementation of cryptography, these type of exploits are called side-channel attacks. People who study cryptanalysis are called cryptanalysts.&lt;/p&gt;

&lt;h3&gt;
  
  
  Methods of Cryptanalysis
&lt;/h3&gt;

&lt;h3&gt;
  
  
  Frequecy Analysis
&lt;/h3&gt;

&lt;p&gt;Frequency Analysis is the study of frequency of letters or group or letters in a ciphertext. This method is relatively older to the newer methods of cryptanalysis. This method is used to break classic ciphers, this method is really useful in breaking substitution ciphers. It is based on the fact that certain letters or group of letters in a specific language text occur with specific frequencies. There is a distribution of the frequencies of letters that occur in a particular language. For example: the letters &lt;code&gt;E&lt;/code&gt;,&lt;code&gt;A&lt;/code&gt;,&lt;code&gt;T&lt;/code&gt; and &lt;code&gt;O&lt;/code&gt; occur the most in a piece of text in the English language. Similarly, the letter pairs - &lt;code&gt;TH&lt;/code&gt;, &lt;code&gt;ER&lt;/code&gt;, &lt;code&gt;ON&lt;/code&gt; and &lt;code&gt;AN&lt;/code&gt; are the most common in a piece of text in the English language, these pairs are reffered to as bigrams.&lt;br&gt;&lt;br&gt;&lt;/p&gt;

&lt;p&gt;In some ciphers, the properties and patters of the plaintext is preserved in the ciphertext, and these patterns can easily be studied and then the cipher can be exploited. The ciphertext usually retains the properties of the plaintext when a single letter always gets encrypted to the same ciphertext letter, this usually occurs in substitution ciphers. This type of attack is called ciphertext-only attack. Ciphertext-only attack is the attack in which the cryptanalyst just has the access to the ciphertext and nothing else. The cryptanalyst, in some cases might also know the language of the plaintext, where the cryptanalyst can use techniques like frequency analysis and index of coincidence.&lt;br&gt;&lt;br&gt;&lt;/p&gt;

&lt;p&gt;When a plaintext is encrypted using a substition cipher, and the cryptanalyst know the actual language of the plaintext, the cryptanalys can easily find frequency distribution and sequences in the ciphertext in most cases. For example: if a ciphertext contains a high frequency of &lt;code&gt;R&lt;/code&gt; in it and the plaintext language was English, the cryptanalyst would know that &lt;code&gt;R&lt;/code&gt; would most probably be &lt;code&gt;E&lt;/code&gt;, &lt;code&gt;T&lt;/code&gt; or &lt;code&gt;A&lt;/code&gt; in the plaintext as these letters occur the most in English, he would still need to try more combinations but frequency distributions make the combinations to try a lot lesser.&lt;/p&gt;

&lt;h3&gt;
  
  
  Index of coincidence
&lt;/h3&gt;

&lt;p&gt;Coincidence counting is a technique related to cryptography. The index of coincidence provides a probability of how likely is it to draw two matching letters by randomly selecting two letters from a given text. The probability of index of coincidence of a specific letter in a text is fully dependent on the number of times that specific letter appears in the string and it also depends on the length of the string the letter is withdrawn from. The probability of index of coincidence is 0.032(3.2%) in completely random text, it is 0.067(6.7%) for English and 0.072(7.2%) for German. The index of coincidence is (number of times that letter appears/ length of the text).&lt;/p&gt;

&lt;h4&gt;
  
  
  Applications
&lt;/h4&gt;

&lt;p&gt;The index of coincidence is useful in the analysis of natural-language plaintext and the analysis of ciphertext. The coincidences in ciphertext can be caused by coincidences in the plaintext. So when coincidences in ciphertext are found, coincidences in the plaintext are also found at the same letter positions. This technique can be used to cryptanalyze the Vigenère cipher.&lt;br&gt;&lt;br&gt;&lt;br&gt;
Index of coincidence can help determine when two texts are written in the same language using the same alphabet. This technique was used to examine the Bible code.&lt;/p&gt;

&lt;h3&gt;
  
  
  Linear Cryptanalysis
&lt;/h3&gt;

&lt;p&gt;Linear cryptanalysis is a method of breaking block and stream ciphers. It is one of the two most widely used attacks on block ciphers. It is a plaintext attack. In Linear Cryptanalysis, the attacker studies the probabilistic linear relations(called linear approximations) between parity bits(bit added to a string of binary code, in the case of DES, the parity bit was added to the binary code to check if the key was indeed correctly retrieved, it was also to check whether during transmission, the wrong keys were used. These bits were used for error detection) of plaintext, the ciphertext and the secret key.&lt;/p&gt;

&lt;h3&gt;
  
  
  Differential Cryptanalysis
&lt;/h3&gt;

&lt;p&gt;Differential cryptanalyis is a method of breaking ciphers. It is primary applicable to block ciphers, but it is also able to break stream ciphers and cryptographic hash functions. It is the study of how differences in the information inputted can affect the output resulting in a different output than common outputs. In the case of a block cipher, it is a set of techniques for tracing the differences through the network of transformation, and finding where the cipher exhibits non-common behaviour and exploiting such properties of the cipher to recover the cryptographic key.&lt;/p&gt;

&lt;h2&gt;
  
  
  Links
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="http://www.facweb.iitkgp.ac.in/~sourav/ldc_tutorial.pdf" rel="noopener noreferrer"&gt;A paper on linear and differential cryptanalysis&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>security</category>
      <category>computerscience</category>
    </item>
  </channel>
</rss>
