Skip to content

Instantly share code, notes, and snippets.

@hellok
Last active May 25, 2018 20:23
Show Gist options
  • Select an option

  • Save hellok/5566260 to your computer and use it in GitHub Desktop.

Select an option

Save hellok/5566260 to your computer and use it in GitHub Desktop.
klingon encrypted with cesars cipher
#include <stdio.h>
#include <string.h>
char* cypheredText[] =
{
"pySpIl. wmqDp oDl! nQSamn lIjngychoIl tDt nDn'Do"
};
char alphabet[] =
{
'a',
'b',
'c',
'd',
'e',
'f',
'g',
'h',
'i',
'j',
'k',
'l',
'm',
'n',
'o',
'p',
'q',
'r',
's',
't',
'u',
'v',
'w',
'x',
'y',
'z'
};
char* keyWords[] = {" what "," is "," the "," of "," by "," to ", " did", " in ", " when ", " how ","flag","here","hello","tlhIngan","nuqneH"};
int attempROT(int rot, int cypheredIndex)
{
char tmpString[1024];
int i;
char currentChar ;
for(i=0 ; i < strlen(cypheredText[cypheredIndex]) ; i++)
{
currentChar = cypheredText[cypheredIndex][i] ;
//Convert to lowercase
if (currentChar >= 65 && currentChar <= 90)
currentChar = currentChar+32;
if (currentChar >= 97 && currentChar <= 122)
{
tmpString[i] = alphabet[ (currentChar + rot) % 26 ] ;
}
else
tmpString[i] = cypheredText[cypheredIndex][i];
}
tmpString[i] = '\0';
//Rotation done, seach for keywords.
for(i= 0 ; i < sizeof(keyWords)/sizeof(char*); i++)
{
if (strstr(tmpString,keyWords[i]))
{
printf("[%d]: Candidate (ROT%d): %s\n",cypheredIndex+1,rot,tmpString);
//printf("Found %s at %d\n",keyWords[i],);
return 1;
}
}
return 0;
}
int main(int argc, char** argv)
{
int i,j;
int numTexts = sizeof(cypheredText) / sizeof(char*);
int found;
for(j=0 ; j < numTexts; j++)
{
//printf("%s\n",cypheredText[j]);
found = 0;
for(i=0 ; i < 26 ; i++)
{
found = found | attempROT(i,j);
}
if (!found)
printf("[%d]: No Candidate.\n",j+1);
}
}
http://fabiensanglard.net/Ghost_in_the_Wires/index.php
http://www.simonsingh.net/The_Black_Chamber/caesar.html
i came, i saw, i conquered
Veni, Vidi, Vici
import time
import re
#Hello we intercepted strange message. Decode it.
#pySpIl. wmqDp oDl! nQSamn lIjngychoIl tDt nDn'Do
key1='a','b','ch','D','e','gh','H','I','j','l','m','n','ng','o','p','q','Q','r','S','t','tlh','u','v','w','y','\'','0','1','2','3','4','5','6','7','8','9','0'
key='a','b','ch','D','e','gh','H','I','j','l','m','n','ng','o','p','q','Q','r','S','t','tlh','u','v','w','y','\''
def returnindex(aa):
index=-1
for z in range(len(key)):
if len(aa)==len(key[z]):
if(aa[:1]==key[z][:1]):
if(aa[1:]==key[z][1:]):
index=z
return index
def returnindex2(aa):
index=-1
if(aa>='a' and aa<='z'):
index=ord(aa)-ord('a')
if(aa>='A' and aa<='Z'):
index=ord(aa)-ord('A')
return index
aa='pySpIl. wmqDp oDl! nQSamn lIjngychoIl tDt nDn\'Do'
# pySpIl. wmqDp oDl! nQSamn lIjngychoIl tDt nDn'Do
#answer:nuqneH. tlhIngan maH! joqwIj Heghlu'meH QaQ jajvam
key1="ABCDEFGHIJKLMNOPQRSTUVWXYZ"
chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"
offset=0
result=''
for offset in range(26):
result1=''
for i in range(len(aa)):
tmp=returnindex(aa[i])
if(tmp!=-1):
result1+=key[(tmp-offset)%26]
else:
result1+=aa[i]
print result1
print "we use offset:3"
time.sleep(1000)
for l in range(len(aa)):
if(returnindex2(aa[l-1].lower())>-1):
result+=key[(returnindex2(aa[l-1].lower())-offset)]
else:
result+=aa[l]
print result
index=-1
for l in range (len(aa)):
index+=1
l=index
if(l<len(aa)):
if(ord(aa[l:l+1])!=ord(' ')):
if(returnindex(aa[l:l+2])>=0):
result+=key[returnindex(aa[l:l+2])-offset]
else:
if(aa[l:l+1]>='a' and aa[l:l+1]<='z'):
if(returnindex(aa[l:l+1])>=0):
result+=key[(returnindex(aa[l:])-offset)%len(key)]
else:
index+=1
else:
if((aa[l:l+1]>='A' and aa[l:l+1]<='Z')):
if(returnindex(aa[l:l+1])>=0):
result+=key[returnindex(aa[l:])-offset]
else:
index+=1
else:
result+=aa[l:l+1]
else:
result+=' '
print result
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment