Skip to content

Instantly share code, notes, and snippets.

View k4rtik's full-sized avatar

Kartik Singhal k4rtik

View GitHub Profile
@k4rtik
k4rtik / due-books.py
Created December 9, 2011 21:30
An attempt to programmatically access NITC library's checkouts section to find out how many books are due by a particular date. Done on September 1, 2011.
# An attempt to programmatically access NITC library's checkouts section to find out how many books are due by a particular date.
# For some reason, the behaviour of the library site was different for different browsers - perhaps identifying and
# using proper browser UserAgent string could have made this script work.
import re
from mechanize import Browser
br = Browser()
br.addheaders = [('User-agent', 'Mozilla/5.0 (X11; Linux x86_64; rv:6.0) Gecko/20100101 Firefox/6.0')]
br.open("http://library.nitc.ac.in:8080/webopac/html/checkouts")
@k4rtik
k4rtik / sqrt.scm
Created December 9, 2011 21:34
My first scheme program, after watching the first HP SICP class video - June 28, 2011
(define (sqrt2 x)
(define (square num)
(* num num))
(define (average a1 a2)
(/ (+ a1 a2) 2))
(define (improve guess)
(average guess (/ x guess)))
(define (good-enough? guess)
(< (abs (- (square guess) x))
.000000001))
@k4rtik
k4rtik / rabinmiller.gp
Created December 9, 2011 21:39
Number Theory & Cryptography - Assignement 2 - Question 1: Implement Rabin-Miller algorithm for Primality Testing. - Done with Aviral - November 9, 2011
/* Question 1: Implement Rabin-Miller algorithm for Primality Testing. */
/*
Input: n>3, an odd number, k for accuracy
Output: 'composite' or 'possibly prime'
*/
rabinmiller(n, k) = {
d = n - 1;
s = 0;
while( (d%2 == 0),
@k4rtik
k4rtik / knapsack.gp
Created December 9, 2011 21:40
Number Theory & Cryptography - Assignement 2 - Question 2: Implement Knapsack Cryptosystem. - Done with Aviral - November 10, 2011
/* Question 2: Implement Knapsack Cryptosystem. */
/*
n - the size of all vectors is fixed at 7.
a is the superincreasing sequence (assumed public key of receiver)
example a:
[1,2,4,8,16,32,64]
m, a 7-bit number - the message to be encrypted
c, ciphertext
@k4rtik
k4rtik / rsa.gp
Created December 9, 2011 21:41
Number Theory & Cryptography - Assignement 2 - Question 3: Implement RSA Cryptosystem. - Done with Aviral - November 10, 2011
/* Question 3: Implement RSA Cryptosystem. */
/*
Call keygen function first.
Use the key generated to encrypt and decrypt message using
corresponding functions.
*/
fastexp(a, x, n) = {
c = 0;
@k4rtik
k4rtik / tictacg.cpp
Created December 9, 2011 21:46
Tic Tac Toe (T3, a game developed in C/C++) (2006-2007) For the school project in C++ in standard 11, I chose to make a game. Although the game doesn't feature AI, it demonstrates the graphics and sound capabilites of C/C++ with Turbo C++ compiler.
/* Link for more info: http://k4rtik.wordpress.com/2009/11/08/my-old-projects/ */
/*
>>>>>>>>>>>>>>>>>>>>Program: Tic Tac Toe<<<<<<<<<<<<<<<<<<<<<
>>>>>>>>>>>>>>>>>Programmer: Kartik Singhal<<<<<<<<<<<<<<<<<<
*/
@k4rtik
k4rtik / endian.c
Created December 9, 2011 23:21
Program to check the endianness of a machine. - January 9, 2011
/*
* endian.c
* Program to check the endianness of a machine.
*
* Copyright (C) 2011 - Kartik Singhal
*
* License: GNU General Public License version 3
*
*/
@k4rtik
k4rtik / ieee754.c
Created December 9, 2011 23:23
Program to check whether the compiler converts a given floating point number to the IEEE 754 specification. - February 25, 2011
/*
* ieee754.c
*
* Program to check whether the compiler converts a given floating point number
* to the IEEE 754 specification.
*
* Original Authors: Mohammed Hashir and Ashwin Jacob
* This is a slightly modified and improved version by
*
* Kartik Singhal - B090566CS
@k4rtik
k4rtik / sicp-download.sh
Created December 10, 2011 00:32
The bash script I created for simultaneously downloading videos of MIT's SICP course. - October 2010
#!/bin/bash
baseurl="http://www.archive.org/download/MIT_Structure_of_Computer_Programs_1986/lec"
urlend="b_512kb.mp4"
log="log_b"
for i in {5..7}
do
nohup wget -c "${baseurl}$i${urlend}" > "${log}$i" &
done
@k4rtik
k4rtik / string-func.cpp
Created December 10, 2011 02:42
generates email IDs and stores them in a file - first year programming assignment - September 23, 2009
// file: string-func.cpp
// generates email IDs and stores them in a file
// author: Kartik Singhal
#include <iostream>
#include <cstring>
#include <fstream>
using namespace std;
int main()