<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Dimuthu Harshamal on Medium]]></title>
        <description><![CDATA[Stories by Dimuthu Harshamal on Medium]]></description>
        <link>https://medium.com/@dimuthuha?source=rss-fd5b280e2019------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*sa_AV1IiBBSrayPl9V3mNA.jpeg</url>
            <title>Stories by Dimuthu Harshamal on Medium</title>
            <link>https://medium.com/@dimuthuha?source=rss-fd5b280e2019------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 23 Nov 2026 04:19:03 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@dimuthuha/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Understanding Rate Limiting: A Deep Dive]]></title>
            <link>https://medium.com/@dimuthuha/understanding-rate-limiting-a-deep-dive-da1f1f59d408?source=rss-fd5b280e2019------2</link>
            <guid isPermaLink="false">https://medium.com/p/da1f1f59d408</guid>
            <category><![CDATA[api-security]]></category>
            <category><![CDATA[java]]></category>
            <category><![CDATA[spring-boot]]></category>
            <category><![CDATA[api]]></category>
            <category><![CDATA[rate-limiting]]></category>
            <dc:creator><![CDATA[Dimuthu Harshamal]]></dc:creator>
            <pubDate>Sun, 31 May 2026 11:46:55 GMT</pubDate>
            <atom:updated>2026-05-31T11:46:55.037Z</atom:updated>
            <content:encoded><![CDATA[<h4>Background</h4><p>Modern applications handle enormous volumes of traffic every day — and not all of it comes from legitimate users.</p><p>Even well-intentioned traffic can be dangerous. A misconfigured client retrying on every error, a mobile app with an infinite loop, or a marketing campaign that drives sudden spikes can all overwhelm a system just as effectively as a deliberate attack.</p><p>Systems must also deal with:</p><ul><li>Accidental request floods from buggy clients</li><li>Bots and crawlers are ignoring crawl delays</li><li>Brute-force attacks against login or OTP endpoints</li><li>Denial-of-Service (DoS) attempts are designed to exhaust resources</li><li>Scraping at scale that degrades performance for real users</li></ul><p>Without protection, a single client can consume a disproportionate share of resources — degrading the service for everyone else, and sometimes bringing the system down entirely.</p><p><strong>Rate limiting</strong> is a protection mechanism that controls how many requests a client can make within a specified period of time. It acts as a traffic control system that protects application resources, ensures fair usage, and improves overall system stability.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/1*RRNrr_qhI2sSegQa2tMYVQ.jpeg" /><figcaption>Road Traffic Control</figcaption></figure><h4>Why Rate Limiting Matters</h4><ul><li>Preventing Abuse — Rate limiting is the first line of defense against brute-force attacks, credential stuffing, and scrapers. By capping how fast a client can interact with sensitive endpoints, you raise the cost of abuse high enough to deter most attackers.</li><li>Protecting Infrastructure— A single misbehaving client should not be able to exhaust your database connections, thread pool, or downstream API quota. Rate limiting puts a hard ceiling on the blast radius of any one client.</li><li>Ensuring Fair Usage— In multi-tenant systems, one heavy user should not crowd out everyone else. Rate limiting enforces fairness at the infrastructure level, independent of application logic.</li><li>Enabling Monetization — Tiered API products (free, pro, enterprise) are built on rate limiting. Different plans get different bucket capacities and refill rates — the same mechanism enforces both protection and product tiers.</li></ul><h4>Key Concepts</h4><ul><li>Rate Limit— The maximum number of requests allowed within one window. A limit of 100 requests per minute means any request that would push the counter past 100 is rejected until the window resets. Limits are usually expressed as requests per second (rps), per minute (rpm), or per day.</li><li>Time Window— The interval used to measure and count requests. Algorithms differ in how they define the window boundary — fixed (hard reset at the boundary) or sliding (rolling lookback from the current moment). The choice of window type determines whether the system is vulnerable to burst attacks at boundaries.</li><li>Identifier — The key used to track “who” is being limited. Common choices:<br>-IP address — for unauthenticated or public endpoints<br>- User ID — for authenticated endpoints<br>- API key — for developer or partner integrations<br>- Session token — for web application flows</li></ul><p>In practice, production systems often apply multiple layers: a strict per-IP limit for unauthenticated endpoints, and a more generous per-user limit for authenticated ones.</p><h4>Rate Limiting Algorithms</h4><ol><li>Fixed Window Counter</li><li>Sliding Window Log</li><li>Sliding Window Counter</li><li>Token Bucket Algorithm</li><li>Leaky Bucket Algorithm</li></ol><p>If you need to dive deep into rate-limiting algorithms -&gt; <a href="https://medium.com/p/48bcf6464bbe?postPublishedType=initial">click</a></p><h4>Distributed Systems Challenge</h4><p>Rate limiting becomes more complicated when multiple application instances exist.</p><p>Ex:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/571/1*zW_veWW_few65g4CZbPwrw.png" /></figure><p>If each server maintains its own in-memory counter, they share no state:</p><p>Limit per user = 100 requests/min</p><p>Server A counter: 100 ✓ allowed<br> Server B counter: 100 ✓ allowed<br> Server C counter: 100 ✓ allowed</p><p>Effective limit the user experiences: 300 requests/min</p><p>Every instance thinks the limit hasn’t been reached, so every instance keeps accepting. The rate limit is effectively multiplied by the number of instances.</p><h4>Distributed Rate Limiting</h4><p>So there should be a centralized solution for that.</p><p>Most commonly, we use:</p><ul><li>Redis</li><li>Infinispan</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/571/1*hN9ygz6Wvze2B_Aqg9z6pw.png" /></figure><p>With a centralized state, all servers share the same counter — a request counted by Server A is immediately visible to Server B and Server C.</p><p>Race condition note<br> — — — — — — — — — -<br>Even with a shared store, naive read-then-write operations are not safe under concurrency:</p><p>Server A reads: count = 99 (below limit)<br> Server B reads: count = 99 (below limit)<br> Server A writes: count = 100 ✓<br> Server B writes: count = 100 ✓ ← both allowed, both should have been checked at 100</p><p>Always use atomic operations to eliminate this race.</p><h4>Rate Limiting in API Design</h4><p>Common HTTP Response :</p><pre>429 Too Many Requests</pre><p>Helpful headers:</p><pre>X-RateLimit-Limit: 100<br>X-RateLimit-Remaining: 25<br>Retry-After: 30</pre><h4>Industry Implementations</h4><p>Many technologies provide built-in rate limiting.</p><p>API Gateways:</p><ul><li>NGINX</li><li>Kong</li><li>Apache APISIX</li></ul><p>Cloud Platforms:</p><ul><li>AWS API Gateway</li><li>Google Cloud API Gateway</li><li>Microsoft API Management</li></ul><p>Java:</p><ul><li>Bucket4J</li><li>Spring Cloud Gateway</li></ul><h4>Bucket4J with Java</h4><p>Bucket4j is a Java library that implements the token bucket algorithm for rate limiting. Each user or client is assigned a bucket that holds tokens. Each request consumes a token from the bucket, and if no tokens are available, the request is denied or delayed until the bucket refills.</p><p>Bucket4j is thread-safe and can be used in either a standalone JVM application or a clustered environment. It also supports in-memory or distributed caching via JCache.</p><p>All calculations are performed in integer arithmetic — no floats or doubles — protecting from rounding errors. It uses a lock-free implementation for multi-threading.</p><p>Dependency:</p><pre>&lt;!-- Java 17+--&gt;<br>&lt;dependency&gt;<br>    &lt;groupId&gt;com.bucket4j&lt;/groupId&gt;<br>    &lt;artifactId&gt;bucket4j_jdk17-core&lt;/artifactId&gt;<br>    &lt;version&gt;8.19.0&lt;/version&gt;<br>&lt;/dependency&gt;</pre><p>Core Concepts:</p><p><strong><em>Bandwidth</em> </strong>— defines one rate limit rule: a capacity and a refill strategy.</p><p>Two refill strategies:<br> <strong><em>refillGreedy</em> </strong>— refills continuously as time passes; allows small bursts between refills<br> <strong><em>refillIntervally</em></strong><em> </em>— refills the full amount only at interval end; strictly periodic</p><p><strong><em>Bucket</em></strong> — holds one or more Bandwidth rules. All rules must pass for a request to be allowed.</p><p>Basic Implementation</p><pre>Bucket bucket = Bucket.builder()<br>    .addLimit(Bandwidth.builder()<br>        .capacity(5)<br>        .refillGreedy(5, Duration.ofMinutes(1))<br>        .build())<br>    .build();<br><br>if (bucket.tryConsume(1)) {<br>    // request allowed<br>    handleRequest();<br>} else {<br>    // request rejected<br>    throw new RateLimitExceededException(&quot;Too many requests&quot;);<br>}</pre><h4>Best Practices</h4><ol><li>Use different limits for different endpoints</li><li>Apply stricter limits to authentication endpoints.</li><li>Use distributed storage for multi-instance deployments.</li><li>Return clear error messages and headers.</li><li>Monitor rate-limiting violations.</li><li>Combine rate limiting with authentication and bot detection.</li></ol><h4>Conclusions</h4><p>Rate limiting is a fundamental reliability and security mechanism in modern distributed systems. While simple approaches such as Fixed Window counters are easy to implement, production-grade systems often rely on Token Bucket or Sliding Window algorithms, combined with distributed stores such as Redis.</p><p>A well-designed rate-limiting strategy not only protects infrastructure from abuse but also ensures fairness, availability, and predictable system performance for all users.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=da1f1f59d408" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Rate Limiting Algorithms Deep Dive]]></title>
            <link>https://medium.com/@dimuthuha/rate-limiting-algorithms-deep-dive-48bcf6464bbe?source=rss-fd5b280e2019------2</link>
            <guid isPermaLink="false">https://medium.com/p/48bcf6464bbe</guid>
            <dc:creator><![CDATA[Dimuthu Harshamal]]></dc:creator>
            <pubDate>Sun, 31 May 2026 11:22:40 GMT</pubDate>
            <atom:updated>2026-05-31T11:22:40.991Z</atom:updated>
            <content:encoded><![CDATA[<p>Multiple algorithms exist for rate limiting, each with different trade-offs between memory, accuracy, and burst tolerance. Before looking at the algorithms, there are five concepts worth knowing.</p><p>KEY CONCEPTS:</p><p>1. <strong>Window</strong><br>A window is the time interval used to measure and count requests — for example, a 60-second window. Algorithms differ in whether this window is fixed (hard boundaries that reset) or sliding (a rolling lookback from the current moment).<br> <br>2. <strong>Limit</strong><br>The maximum number of requests allowed within one window. A limit of 100 requests per minute means any request that would push the counter past 100 is rejected until the window resets.<br> <br>3. <strong>Identity scope</strong><br>Rate limits can apply globally (all traffic shares one counter) or per identity. The most common scopes are:<br>- User ID — for authenticated endpoints<br>- IP address — for public or unauthenticated endpoints<br>- API key — for developer or partner integrations<br> <br>4. <strong>Strategy</strong><br>When the limit is hit, the system can either block the request outright (returning HTTP 429 Too Many Requests) or slow it down by adding latency before processing — a technique called throttling.<br> <br>5. <strong>Burst attack</strong><br>A burst attack exploits a hard window boundary. With a fixed 60-second window and a limit of 100 requests, a client can send 100 requests at t=59s (end of window 1) and another 100 at t=61s (start of window 2) — 200 requests in 2 seconds, never technically violating the rule. Algorithms that use a sliding window or a token model are immune to this.</p><h4>Fixed Window Counter</h4><p>Core concept:</p><p>You have a counter and a clock. Divide time into equal-sized buckets. Every request in that bucket increments the count. When the bucket expires, reset to zero.</p><p>How it Works:</p><p>On each incoming request, the current timestamp is floored to a window ID:</p><p>window_id = floor(current_time / window_size) * window_size</p><p>The counter for (user, window_id) is fetched. If it is below the limit, it is incremented, and the request is allowed. If it equals the limit, the request is rejected.</p><p>Incoming request<br> → compute window_id<br> → GET counter for (user, window_id)<br> → counter &lt; limit? → increment → ALLOW<br> → counter &gt;= limit? → REJECT (429)</p><p>Data Structure:</p><p>A single integer per user per window, stored with a TTL equal to the window size. Memory cost is O(1) per user.</p><p>key = “rl:user:alice:1748563200”<br> value = 3<br> TTL = 60s</p><p>Strengths: O(1) memory, O(1) time per request, dead simple to implement and debug.</p><p>Weaknesses: Vulnerable to the burst attack — a client can push 2× the limit across a window boundary.</p><p>When to use it:<br>Fixed window is appropriate for coarse limits (e.g., 10,000 requests per day) where a 2× edge burst is tolerable, or for simple internal tooling where precision is not critical.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*CBiw__AXfo563zpz4z_7DQ.png" /></figure><h4>Sliding Window Log</h4><p>Core Concept:</p><p>Instead of a single counter that resets, keep a log of exact timestamps for every request. On each new request, look back exactly N seconds and count what’s in that range.</p><p>How it works:<br> Incoming request at time T<br> → remove all timestamps older than (T — window_size)<br> → count remaining timestamps<br> → count &lt; limit? → add T to log → ALLOW<br> → count &gt;= limit? → REJECT (429)</p><p>Data structure:<br>A sorted set of timestamps per user, typically stored as a Redis Sorted Set (ZADD / ZREMRANGEBYSCORE / ZCARD).</p><p>key = “rl:user:alice”<br> value = sorted set: { 1748563200.1, 1748563203.4, 1748563208.9 }</p><p>Why is there no burst attack?<br>Because the log remembers every timestamp, there is no hard boundary to exploit. At t=61s, looking back 60 seconds includes everything from t=1s onward — requests fired at t=59s are still counted and contribute to the limit.</p><p>Strengths:<br>Mathematically precise — no edge cases, no boundary exploits, perfect accuracy.</p><p>Weaknesses:<br>Memory grows with traffic. At 100 req/min per user and 1M users, the log holds ~100M timestamps (~6 GB RAM). Not practical at scale.</p><p>When to use it:<br>Low-traffic, high-stakes endpoints where accuracy is non-negotiable: OTP generation, payment initiation, authentication.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/591/1*2UBX4CGcPzPvntmdGWkOgQ.png" /></figure><h4>Sliding Window Counter</h4><p>Core Concept:</p><p>A hybrid between a fixed window (low memory) and a sliding window log(accurate). Instead of storing every timestamp, store just two counters, the current window and the previous one, then interpolate to estimate how requests happened in the last N seconds.</p><pre>estimated = prev_count × (1 − position) + curr_count<br><br>where position = (current_time % window_size) / window_size</pre><p>The formula assumes requests were evenly spread across the previous window. In practice, Cloudflare’s research shows the error stays within 0.003% on real traffic.</p><p>How it actually works:</p><p>— — — — — — <br> Incoming request at time T<br> → position = (T % window_size) / window_size<br> → estimated = prev_count × (1 − position) + curr_count<br> → estimated &lt; limit? → increment curr_count → ALLOW<br> → estimated &gt;= limit? → REJECT (429)</p><p>Data structure:<br>Two integers per user. Memory cost is O(1) regardless of traffic volume.</p><p>rl:user:alice:prev = 4 (previous window)<br> rl:user:alice:curr = 2 (current window)</p><p>Example:<br>Limit: 5 requests per 10s. The previous window had 4 requests. Current window has 1 request. You are 3 seconds into the current window (30% through):</p><p>position = 3/10 = 0.3<br> weight = 1 − 0.3 = 0.7<br> estimated = 4 × 0.7 + 1 = 3.8 → below 5 → ALLOW</p><p>Strengths:<br>O(1) memory, O(1) time, near-perfect accuracy (~99.997%), immune to burst attacks. 400× less memory than a sliding window log at scale.</p><p>Weaknesses:<br>Slightly approximate — assumes even distribution of requests within each window.</p><p>When to use it:<br>High-traffic production APIs where sliding window log memory costs are prohibitive. This is the algorithm used by Cloudflare and many large API platforms.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/591/1*HItK8pCymqY_Zjgt3jTPQQ.png" /></figure><h4>Token Bucket</h4><p>Core Concept:</p><p>Imagine a bucket that fills with tokens at a steady rate. Each request consumes one token. If the bucket has tokens, the request goes through. If it’s empty, the request is rejected(or delayed).</p><p>Two parameters control everything:<br>- Capacity — the maximum number of tokens (and therefore the maximum burst size)<br>- Refill rate — tokens added per second (the sustained throughput)</p><p>How it actually works:</p><p>Tokens are not added on a timer. Instead, the number of tokens earned since the last request is calculated lazily on each request:</p><p>elapsed = current_time — last_refill<br> new_tokens = elapsed × refill_rate<br> tokens = min(capacity, stored_tokens + new_tokens)</p><p>if tokens &gt;= 1:<br> tokens -= 1 → ALLOW<br> else:<br> REJECT (429)</p><p>Data structure: <br>Two floats per user. Memory cost is O(1).</p><p>rl:user:alice:tokens = 3.5<br> rl:user:alice:last_refill = 1748563200</p><p>Burst behaviour:<br>Token bucket explicitly allows bursts up to the bucket capacity. A user who has been idle for 10 seconds with a refill rate of 1/sec and a capacity of 10 will have earned a full bucket — the right to fire 10 requests instantly. This is intentional and is the algorithm’s defining feature.</p><p>Capacity = 10, Refill = 1/sec</p><p>User idle for 10s → bucket fills to 10<br> User fires 10 requests instantly → all allowed ✓</p><p>Strengths:<br>Allows natural bursts. O(1) memory. Two intuitive knobs (capacity and rate) that can be tuned per endpoint.</p><p>Weaknesses:<br>Burst traffic passes directly through to the server. If the server cannot absorb a sudden spike, pair this with a connection limit or queue.</p><p>Real-world usage: <br>AWS API Gateway, Stripe, Shopify Storefront API, and GitHub REST API all use a token bucket or a close variant as their primary rate-limiting algorithm.</p><p>When to use it:<br>Any REST API where occasional bursts are acceptable — which covers most of them. Token bucket matches how real user traffic behaves: a calm baseline with occasional spikes.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/551/1*4DNZs2ZuklhxLuCL4hA6Jg.png" /></figure><h4>Leaky Bucket</h4><p>Core Concept:</p><p>Requests pour into a queue(bucket). A worker drains the queue at a fixed constant rate, like water leaking from a hole at the bottom. No matter how fast requests come in, they exit at a steady pace.</p><p>Two parameters:<br>- Bucket size — the maximum queue length (overflow is rejected)<br>- Leak rate — how many requests are processed per second</p><p>How it works:</p><p>Like a token bucket, the drain is calculated lazily on each incoming request:</p><p>elapsed = current_time — last_leak<br> leaked = elapsed × leak_rate<br> queue_count = max(0, queue_count — leaked)</p><p>if queue_count &lt; bucket_size:<br> queue_count += 1 → ALLOW (queued)<br> else:<br> REJECT (overflow)</p><p>Smoothing behaviour:<br>The output rate is always constant, regardless of input spikes:</p><p>Token bucket: ████████░░░░░░░░████ (mirrors bursts)<br> Leaky bucket: █░█░█░█░█░█░█░█░█░█░ (always even)</p><p>This makes the leaky bucket the only algorithm that provides hard throughput guarantees to downstream systems.</p><p>The latency trade-off:<br>Smoothing comes at a cost: queued requests wait. With a bucket size of 100 and a leak rate of 10/sec, the last request in a full burst waits 10 seconds. For interactive APIs, a 10-second delay is worse than an outright rejection.</p><p>Strengths:<br>Constant output rate. The server never sees spikes. Predictable processing order (FIFO).</p><p>Weaknesses:<br>Latency grows under load. Poor fit for interactive or real-time APIs.</p><p>When to use it:<br>Network traffic shaping (routers, CDNs), video streaming buffers, print queues, and background job processors — any context where throughput smoothness matters more than latency.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/551/1*RPJkKgs0Xuqu_RGLqv8PNQ.png" /></figure><p>Comparison:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/946/1*labjJ6kqVaU1vap5CJKxeg.png" /></figure><p>When to use which:</p><ul><li><strong>Token Bucket</strong> → APIs where bursts are acceptable (most REST APIs, AWS, Stripe)</li><li><strong>Leaky Bucket</strong> → Network traffic shaping where smoothness matters</li><li><strong>Sliding Window</strong> → Strict per-user quotas (auth endpoints, payment APIs)</li><li><strong>Fixed Window</strong> → Simple internal tools where precision isn’t critical</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=48bcf6464bbe" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[The Math Behind RSA: A Step-by-Step Guide to Public Key Cryptography]]></title>
            <link>https://medium.com/@dimuthuha/the-math-behind-rsa-a-step-by-step-guide-to-public-key-cryptography-181e264b86a0?source=rss-fd5b280e2019------2</link>
            <guid isPermaLink="false">https://medium.com/p/181e264b86a0</guid>
            <category><![CDATA[rsa-algorithm]]></category>
            <category><![CDATA[information-security]]></category>
            <category><![CDATA[public-key-cryptography]]></category>
            <category><![CDATA[diffie-hellman]]></category>
            <category><![CDATA[cryptography]]></category>
            <dc:creator><![CDATA[Dimuthu Harshamal]]></dc:creator>
            <pubDate>Thu, 10 Apr 2025 12:14:59 GMT</pubDate>
            <atom:updated>2026-02-13T12:04:29.953Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5vcNbh64bikIFdq1dAjzug.jpeg" /></figure><p>The <strong>RSA Algorithm</strong> is a cornerstone of modern-day cryptography. It is an <strong>asymmetric key cryptographic algorithm</strong>, meaning it uses a <strong>pair of keys, </strong>a public key and a private key, for secure communication. RSA was invented in 1977 by three brilliant cryptographers: <strong>Ron Rivest</strong>, <strong>Adi Shamir</strong>, and <strong>Leonard Adleman</strong>, and its name “RSA” is derived from the initials of their surnames.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/300/1*36OotyZsmedIr1cOjB5F2g.jpeg" /><figcaption>Inventers of RSA</figcaption></figure><h3>A Bit of History</h3><p>Before RSA, most cryptographic systems relied on symmetric key algorithms, where the same key was used for both encryption and decryption. However, this posed a major challenge — <strong>key distribution</strong>. If the key was intercepted during transmission, the entire communication could be compromised.</p><p>RSA was the first <strong>practical public key cryptosystem</strong>, and it changed everything. For the first time, people could communicate securely over insecure channels without needing to share a secret key in advance. It laid the groundwork for secure digital communications, enabling everything from <strong>secure emails</strong> and <strong>digital signatures</strong> to <strong>SSL/TLS protocols</strong> used in web browsers today.</p><h3>Importance of RSA</h3><ul><li><strong>Security Foundation</strong>: RSA is used in most of today’s secure communication systems.</li><li><strong>Encryption and Digital Signatures</strong>: It enables not only confidentiality (through encryption) but also integrity and authenticity (through digital signatures).</li><li><strong>Widespread Adoption</strong>: RSA is used in protocols such as HTTPS, SSL/TLS, SSH, PGP, and many more.</li></ul><h3>How Does RSA Work?</h3><p>Imagine Alice wants to send a secret message to Bob. She encrypts the message using <strong>Bob’s public key</strong>, and Bob decrypts it using his <strong>private key</strong>, which only he knows. Even if someone intercepts the message, they cannot decrypt it without the private key.</p><h3>Mathematical Explanation of RSA</h3><p>Let’s walk through a simplified example to understand how RSA works. Note that in practice, much <strong>larger prime numbers</strong> are used to ensure security.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*MOpccsPIxjDXHyrt_esXNw.png" /></figure><h3>1. Key Generation (Bob’s Side)</h3><p>Bob needs to generate a <strong>public key</strong> (e, n )and a <strong>private key</strong> (d, n).</p><h4>Step 1: Choose Two Prime Numbers</h4><p>Choose two prime numbers, p and q.</p><p>Let’s take:<br> p = 13<br> q = 7</p><h4>Step 2: Compute n</h4><p>n = p * q <br>n = 13 * 7 = 91</p><h4>Step 3: Compute Euler’s Totient Function Φ(n)</h4><p>Φ(n) = (p — 1)(q — 1) <br>Φ(n) = (13–1)(7–1) = 12 * 6 = 72</p><h4>Step 4: Choose a Private Key d</h4><p>The private key d must satisfy:</p><ul><li>1 &lt; d &lt; Φ(n)</li><li>gcd(d, Φ(n)) = 1 (i.e., d must be relatively prime to Φ(n))</li></ul><p>Let’s choose d = 11.</p><h4>Step 5: Compute the Public Key e</h4><p>We now find the modular inverse of d mod Φ(n):</p><p>e * d ≡ 1 mod Φ(n)<br>e * 11 ≡ 1 mod 72</p><p>Using the <strong>Extended Euclidean Algorithm</strong>, we find:</p><p>e ≡ 59 mod 72</p><p>So now we have:</p><ul><li><strong>Public Key</strong>: (e, n) = (59, 91)</li><li><strong>Private Key</strong>: (d, n) = (11, 91)</li></ul><h3>2. Message Encryption (Alice’s Side)</h3><p>Let’s say the message is <strong>“Hey”</strong>.</p><h4>Step 1: Convert Message to ASCII</h4><p>H e y <br>72 101 121</p><h4>Step 2: Encrypt Each Character</h4><p>Using the formula:<br> C = M^e mod n</p><p>CH = 72⁵⁹ mod 91 = 67 <br>Ce = 101⁵⁹ mod 91 = 82 <br>Cy = 121⁵⁹ mod 91 = 88</p><p>C = [67, 82, 88]</p><h3>3. Message Decryption (Bob’s Side)</h3><p>Bob decrypts the message using his private key (d, n).</p><p>Using the formula:<br> M = C^d mod n</p><p>M1 = 67¹¹ mod 91 = 72 <br>M2 = 82¹¹ mod 91 = 101 <br>M3 = 88¹¹ mod 91 = 121</p><p>72 101 121</p><p>M = “Hey”</p><h3>Final Thoughts</h3><p>This example uses small primes for simplicity, but <strong>in real-world scenarios, RSA uses prime numbers that are hundreds of digits long</strong>. The security of RSA relies on the <strong>computational difficulty of factoring large composite numbers, </strong>a problem that classical computers cannot efficiently solve, making RSA a robust and secure cryptographic system.</p><p>RSA continues to play a <strong>crucial role in cybersecurity</strong>, and understanding its core principles is fundamental for anyone diving into <strong>computer science, cryptography, or information security</strong>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=181e264b86a0" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[After One Year of Computer Science Major]]></title>
            <link>https://medium.com/@dimuthuha/after-one-year-of-computer-science-major-4742f32b03b4?source=rss-fd5b280e2019------2</link>
            <guid isPermaLink="false">https://medium.com/p/4742f32b03b4</guid>
            <category><![CDATA[college-life]]></category>
            <category><![CDATA[university-life]]></category>
            <category><![CDATA[university]]></category>
            <category><![CDATA[computer-science]]></category>
            <category><![CDATA[computer-science-student]]></category>
            <dc:creator><![CDATA[Dimuthu Harshamal]]></dc:creator>
            <pubDate>Thu, 16 May 2024 17:16:09 GMT</pubDate>
            <atom:updated>2024-05-16T17:16:09.930Z</atom:updated>
            <content:encoded><![CDATA[<p>First, when I came to study computer science, I didn’t know much about what this course required because I studied Mathematics, Physics, and Chemistry in high school. After that, I decided to select a computer science degree to study. Before I joined the course I thought computer science was all about programming which is wrong though.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*J6A_T-Xb3nRTW09jZbzHVA.jpeg" /></figure><p>First of all, I will tell you about university life. In my point of view, going to a university is a good decision for me because of the several benefits I get. The main thing is the organized curriculum. As You all know, Most of the lessons in the Computer Science degree can learned online. But the thing is there are lots of resources on the internet because of that we can’t focus on what lessons we should study and practice and what are not. And also some classes are mandatory for a computer science student to learn which is the basics of the degree we all need to understand. In university, we have a fixed curriculum. I think most of its classes are relevant. Also, Universities have well-educated lectures with various subject expertise. They are always willing to help you. You have the responsibility to get the help if you needed. In the first year, most of the subjects are designed to understand the basics of computer science. What I learned most in the first year is Data Structures and Algorithms from Arrays to Graphs and Tree variations. And also Object-oriented programming, Operating Systems, Databases, Software Development lifecycle, and Some Discrete maths and linear algebra. As you all know those are some basic things about Computer science. (My favorite one was Data Structures and Algorithms ngl.)</p><p>Another benefit is getting to know some cool peer groups. Because when you are learning alone, you don’t have access to get to know like-minded IT communities (most of the time). Getting to know each other is cool at the same time beneficial. It may increase your opportunity to find an internship as well. Another cool thing about interacting with people is you gain lots of social skills, leadership skills, and many more. After all University life without friends is freaking boring. And also, you can join community clubs to meet new people and work together for betterment. So those are some things you can do in the university to grow your network. this is not only for Computer science students but also all the students who study various majors in their universities.</p><p>Industry Exposure is one of the benefits of the University. Having the Industry closer to you is a blessing. because when you are going to an internship you already know what the industry expects from you which helps grow your skills. If your university is well-reputed or close to the city, there will be a huge chance to get that exposure. Recruiters love to hire people from well-reputed universities because of their history and alumni. So when you choose your university, make the decision wisely regardless of your major, it will directly affect the early stage of your career.</p><p>There are so many things you can do in your university life like sports, volunteering, and many more.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1z08kAe2R9R2HyJoKecQbw.jpeg" /></figure><p>Now Let’s focus on what should you learn before you enter the university. I can say nothing because most university curriculums have the basics of the degree to be learned. But if have a curiosity to learn things related to computer science, here are some recommendations from me. So basically you can start to learn some programming language. I prefer C or C++ because both are low-level languages that are helpful for you to understand programming concepts like control structures, variables, loops, and many more. And also you will find it easy to learn a new language after you learn a language like C properly. Another thing you can learn is discrete maths which is a subject some students find difficult. Discrete maths is not exactly a math you think. Discrete mathematics is used to study the complexity of algorithms, which measures how long an algorithm takes to run as a function of the input size. This is important because algorithms with good complexity are more efficient and can run faster on larger inputs. You can learn those subjects on YouTube. there are several channels you can find on YouTube.</p><p>And there are coding competitions AKA hackathons you can participate in and gain some experience. Also if you win, you will earn cash prizes as well. Another main thing to focus on is personal finance. As a young adult, you have to earn some money for your expenses. because asking for money from parents as an adult is not a good idea at all. So you can do several things with your strict schedule. Tuition, Online freelancing, Photography, Modeling, and announcing are some of the side hustles. Managing your money carefully is as important as earning money. As young adults, we all love to have fun and buy expensive things but we need to be careful with that.</p><p>So this is the advice I can give you after the first year of a Computer Science major. Hope you get some ideas about the things you should do, What you gonna study, and what you won&#39;t need to do.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4742f32b03b4" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[OOP vs Procedural Programming]]></title>
            <link>https://medium.com/@dimuthuha/oop-vs-procedural-programming-d7b61b5ac05f?source=rss-fd5b280e2019------2</link>
            <guid isPermaLink="false">https://medium.com/p/d7b61b5ac05f</guid>
            <category><![CDATA[oop-concepts]]></category>
            <category><![CDATA[computer-science]]></category>
            <category><![CDATA[oops-concepts]]></category>
            <category><![CDATA[oop]]></category>
            <category><![CDATA[oop-vs-pop]]></category>
            <dc:creator><![CDATA[Dimuthu Harshamal]]></dc:creator>
            <pubDate>Mon, 29 Apr 2024 12:38:08 GMT</pubDate>
            <atom:updated>2024-04-29T12:40:50.506Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*kKVhMC1KbgTLUKZZmiWRuw.png" /></figure><p><strong>What is Procedural Programming?</strong></p><p>A program in procedural programming is a set of instructions. Each statement in the program tells the computer to do something like add two numbers, get inputs from the user, print something, etc.</p><p>Programs must be divided into small subprograms, procedures, or functions when they become complex. Each function has a clearly defined purpose about what to do with the function.</p><p><strong>What are the drawbacks of Procedural Programming?</strong></p><p>In procedural programming, We mainly focus on functions. Functions have unrestricted access to global data which is not secure. Unrelated functions and data, are the basis of the procedural paradigm and provide a poor model to the real world.</p><p>Also, the Large number of connections makes the program more complex. Program structure is difficult to conceptualize.</p><p>A change made in a global data item may necessitate rewriting all the functions that access that item.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/501/1*9HImkKCLrGUbD1VdDeTKOw.png" /><figcaption>Global Data usage by functions in Procedural programming</figcaption></figure><p><strong>What is a programming paradigm?</strong></p><p>The way you write the program or an approach to solve problems using programming languages.</p><p><strong>What is the solution to this Problem?</strong></p><p>So, We can change the approach of writing the computer program from procedural programming into a much better paradigm called Object-oriented programming.</p><p><strong>What is Object-Oriented Programming?</strong></p><p>Object-oriented programming (OOP) is a programming paradigm that organizes software design around objects rather than actions and data rather than logic. In OOP, objects are instances of classes, which encapsulate data for the object and define methods to operate on that data.</p><p><strong>What are the advantages of OOP?</strong></p><p>It is faster and easier to execute and it provides a clear structure to the program by using classes. Also, OOP makes the code easy to maintain, modify, and debug. Most importantly, Makes it possible to create reusable applications with less code and shorter development time.</p><p><strong>Compare &amp; Contrast</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/897/1*ydngM0ScBKatfo3uZdOcmA.png" /><figcaption>comparizon</figcaption></figure><p>We will see more about OOP in the next articles!!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d7b61b5ac05f" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[About Me — Dimuthu Harshamal]]></title>
            <link>https://medium.com/@dimuthuha/about-me-dimuthu-harshamal-dbb14355d36e?source=rss-fd5b280e2019------2</link>
            <guid isPermaLink="false">https://medium.com/p/dbb14355d36e</guid>
            <category><![CDATA[computer-science]]></category>
            <category><![CDATA[about]]></category>
            <category><![CDATA[about-me]]></category>
            <category><![CDATA[about-me-stories]]></category>
            <dc:creator><![CDATA[Dimuthu Harshamal]]></dc:creator>
            <pubDate>Sun, 28 Apr 2024 15:03:03 GMT</pubDate>
            <atom:updated>2025-04-10T12:16:59.086Z</atom:updated>
            <content:encoded><![CDATA[<h3>About Me — Dimuthu Harshamal</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/400/1*C6TBSm_QAxtmEJUwxl3xMQ.png" /></figure><p>Hi there!</p><p>I’m Dimuthu from Sri Lanka Currently studying Computer Science at the University of Colombo.</p><p>As a Gen Z born I didn’t love to write much. But recently I have had a craving to find a new hobby during my vacation because I was so bored. That’s where I find writing is also something interesting.</p><p>Back in my school days, I was good at Math and Science. Also, I have good memories of playing chess, and puzzling. So I decided to do a computer science degree which is a bit controversial today with my decision because of the lack of social interactions with this career. But I love the subjects I have studied so far.</p><p>As the only child in the family, I had lots of free time with myself to do anything in my life. But there is a regret of not getting a sibling to share my feelings.</p><p>Also, I love to read and watch philosophy, life, and history which catches my interest but not as a school subject which is my least favorite for me. Maybe I will write things about those topics as well.</p><p>Here I write more about computer science-related content like OOP, DSA, Operating systems, etc.</p><p>Feel free to reach out to me on any platform. I’d love to help people with my knowledge.</p><p>Connect or follow me on: <a href="https://www.linkedin.com/in/dimuthuharshamal/">LinkedIn</a> <a href="https://www.instagram.com/dimuthuha/">Instagram</a> <a href="https://www.threads.net/@dimuthuha">Threads</a> <a href="https://twitter.com/dimuthuip">X</a></p><p>Until then, Good luck to all of you!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=dbb14355d36e" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>