Welcome, guest | Sign In | My Account | Store | Cart

Code_Fouad_Teniou program allows you to encrypt and decrypt text by using a key ( made_key). However, the key is a set of numbers selected at random and the program allows you to create an infinity numbers of this key, which make the code impossible to crack. Though, I used a metaclass to access the methods used in my program to allow permutation of such methods in a way to perform desirable tasks and in a specific order to suit the need of the programmer’s outcome.

Python, 130 lines
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
#On the name of ALLAH and may the blessing and peace of Allah 
#be upon the Messenger of Allah Mohamed Salla Allahu Aliahi Wassalam.
#Author : Fouad Teniou
#Date : 13/10/09
#version :2.6.1

"""
Code_Fouad_Teniou class uses a function made_key, to  generate a
random key every time you try to encrypt a text, by using FtEncrypt
function and it uses the same key to decrypt the same text by using
the FtDecrypt method.
The metaclass allows a special access to these methods.
"""
import random

class Code_Fouad_Teniou(object):
    """
    Class that represent a code of encryption and decryption
    using a made_key method
    """
    my_list = []
    my_key = []
    my_dict = {}
    
    def made_key(self):
        """
        A method to create a set of values
        and return a random' key 
        """
        
        # select a random number from 1 to infinity 
        ran_number = random.randint(1,99)

        # create a random set based on the first number you chose       
        set = xrange(ran_number,28*ran_number,ran_number)

        # increase the value of every number in the set        
        for item in set:
            item += 3
            Code_Fouad_Teniou.my_key.append(item)

        #return a random key         
        return Code_Fouad_Teniou.my_key

    def FtEncrypt(self,text):
        """ Encrypt a text into a list of values """
        
        self.text = text
        EncryptText = []
        characters = "abcdefghijklmnopqrstuvwxyz "

        #attempt to append my_list and update my_dict
        #using a random set of alphabet and a random made_key         
        try:
            for char in random.sample(characters,27):
                Code_Fouad_Teniou.my_list.append(char)
           
            Code_Fouad_Teniou.my_dict.update(zip(Code_Fouad_Teniou.my_key,Code_Fouad_Teniou.my_list))

            for item in text.lower():
                for i in Code_Fouad_Teniou.my_dict.items():
                    if item == i[1]:
                        EncryptText.append(i[0])
                    
            return EncryptText
        
        #Raise AttributeError if text is not a string 
        except AttributeError:
            raise AttributeError, "\n<Please re-enter your text as a 'string'"
        
    def FtDecrypt(self,EncryptText):
        """ Decript a list of values into the orginal text """
     
        self.EncryptText = EncryptText
        characters = "abcdefghijklmnopqrstuvwxyz "
        DecripText = ''

        #attempt to decrypt the text using the made_key and EncryptText        
        try:
            for item in self.EncryptText:
                DecripText += Code_Fouad_Teniou.my_dict[item]

            return DecripText
        
        #Raise KeyError if a different key was used to encrypt the text 
        except KeyError:
            print "\n<Please use the right code(made_key) to decrypt your text"
    
# Allowing Access of class Code_Fouad_Teniou Methods
def Method_Access(function):
    """ Attempted operation to access a function """
    
    pass

class AccessMeta(type):
  
    def __new__(cls,names,bases,namespaces):

        for item in bases:
            if isinstance(item,AccessMeta):
                pass 

            else:                
                for code in namespaces['code_steps']:
                    if code in namespaces:
                        pass
                    
                    else:
                        namespaces[code] = Method_Access(getattr(item,code))
        
        return super(AccessMeta,cls).__new__(cls,names,bases,namespaces)

class Access:
    __metaclass__ = AccessMeta

if __name__ == "__main__":
  
    class AccessAppend(Access,Code_Fouad_Teniou):
        cft = Code_Fouad_Teniou()
        code_steps = "made_key FtEncrypt FtDecrypt ".split()
  
    AccessAppend().cft.made_key()
    
    encrypt =  AccessAppend().cft.FtEncrypt('hello world')
    print encrypt
    
    decrypt = AccessAppend().cft.FtDecrypt(encrypt)
    print decrypt
    
#######################################################################

21 comments

Fouad Teniou (author) 14 years, 3 months ago  # | flag

Mr Fouad Teniou new link:

1-Profile

2-Career

3-Photos

4-Pi Quotation

5-Beyond Space Project

6-Door's shape Design (photoshop art work) and quotation

https://acrobat.com/#d=aEjxtq78QkGKUxa*UprkZQ

Rodney Drenth 14 years, 3 months ago  # | flag

What you have implemented is a form of substitution cypher link. Albeit the mapping between plaintext and cyphertext is chosen randomly. There exist programs that will crack this type of cypher quite easily, given a fair amount of encrypted text.

Fouad Teniou (author) 14 years, 3 months ago  # | flag

Thank you,

However, I invented the code_Fouad_Teniou for my own personal use and decided to share it with others, the fact that it is impossible to crack, while others knowing the code.

This is because, it generates an infinity numbers of keys by increasing the random number range ( ran_number = random.randint(1,9999….) ), and no computer is able to crack infinity.

Gabriel Genellina 14 years, 3 months ago  # | flag

ran_number (and the my_key list) aren't important at all; you might as well use 28 arbitrary Chinese characters for what matters. The real encription happens in the random.sample(characters, 27) line, which scrambles the letters <--> numbers mapping. As someone already pointed out, a simple substitution cipher like this can be easily reversed when enough encrypted text is available - you may be interested in Al-Kindi, a Muslim mathematician from IX century who solved this problem; see http://www.simonsingh.net/The_Black_Chamber/crackingsubstitution.html

A shorter version that does exactly the same as yours:

import string
import random

key = list(string.ascii_lowercase + " ")
random.shuffle(key)
base = random.randint(1,99)
fwdict = dict(zip(key, range(base+3, base*28+3, base)))
rvdict = dict((v,k) for (k,v) in fwdict.items())
def encode(s): return [fwdict[c] for c in s.lower() if c in fwdict]
def decode(x): return ''.join(rvdict[n] for n in x)

original = "hello world!"
encoded = encode(original)
print encoded
# [1263, 591, 927, 927, 1515, 2271, 2103, 1515, 1599, 927, 675]
decoded = decode(encoded)
print decoded
# hello world
Rodney Drenth 14 years, 3 months ago  # | flag

The following is a Code_Fouad_Teniou encrypted message. [165,159,27,27,9,15,123,165,57,147,129,51,87,153,69,147,123, 33,147,15,117,27,147,75,51,123,57,9,159,87,75,9,27,69,147, 9,135,15,57,147,111,27,57,57,153,165,27,147,153,57,147,153, 147,75,135,153,33,33,27,123,165,27,147,9,51,147,153,75,9,15, 117,27,57,9,153,9,27,147,159,27,153,69,27,159,57,147,153,123, 69,147,153,57,147,153,123,147,123,33,147,27,93,153,111,105,33, 27,147,9,51,147,57,135,51,39,147,21,51,87,147,21,51,87,159, 147,75,21,105,135,27,159,147,15,57,147,123,51,9,147,87,123, 141,159,27,153,45,153,141,33,27,147,123,33,147,15,147,27,93, 105,27,75,9,147,9,135,15,57,147,111,27,57,57,153,165,27,147, 9,51,147,141,27,147,99,87,15,75,45,33,21,147,69,27,75,159, 21,105,9,27,69,147,153,123,69,147,9,135,27,147,105,33,153,15, 123,9,27,93,9,147,105,51,57,9,27,69,147,141,153,75,45,147, 123,33,147,51,123,147,153,75,9,15,117,27,57,9,153,9,27,147, 147,9,51,147,105,51,57,9,27,159,147,105,33,27,153,57,27,147, 105,87,9,147,153,147,123,27,39,33,15,123,27,147,153,129,9,27, 159,147,153,123,21,147,123,33,147,21,51,87,147,57,27,27,147, 123,33,147,141,21,147,69,27,9,27,159,111,15,123,15,123,165, 147,9,135,27,147,165,159,27,153,9,27,57,9,147,75,51,111,111, 51,123,147,69,15,117,15,57,51,159,147,51,129,147,9,135,27, 147,69,15,129,129,27,159,27,123,75,27,147,141,27,9,39,27,27, 123,147,153,123,21,147,9,39,51,147,123,33,147,75,51,69,27,57, 147,51,123,27,147,75,153,123,147,27,153,57,15,33,21,147,69, 27,9,27,159,111,15,123,27,147,39,135,153,9,147,9,135,27,147, 117,153,33,87,27,147,51,129,147,21,51,87,159,147,159,153,123, 123,87,111,141,27,159,147,39,153,57,147,123,33,147,153,57,147, 165,153,141,159,15,27,33,147,105,51,15,123,9,27,69,147,51,87, 9,147,9,135,27,147,75,135,153,33,33,27,123,165,27,147,15,57, 147,9,51,147,69,27,9,27,159,111,15,123,27,147,9,135,27,147, 111,153,105,105,15,123,165,147,141,27,9,39,27,27,123,147,123, 33,147,9,135,27,147,75,51,69,27,57,147,153,123,69,147,9,135, 27,147,33,153,9,15,123,147,33,27,9,9,27,159,57,147,147,45, 123,51,39,15,123,165,147,9,135,27,147,129,159,27,99,87,27, 123,75,21,147,51,129,147,87,57,27,147,51,129,147,117,153,159, 15,51,87,57,147,123,33,147,33,27,9,9,27,159,57,147,153,123, 69,147,75,51,111,111,51,123,147,39,51,159,69,57,147,27,57, 105,27,75,15,153,33,33,21,147,57,135,51,159,9,147,51,123,27, 57,147,123,33,147,159,27,165,153,159,69,57,147,123,33,147,159, 51,69,123,27,21,147,69,159,27,123,9,135,147]

Andreas Tawn 14 years, 3 months ago  # | flag

This took about 10 mins and I'm very far from being a cryptologist. I don't think I'd be happy to use this for anything I wanted to keep secret.

GREETINGS FOUAD

IVE CONSTRUCTED THIS MESSAGE AS A CHALLENGE TO ACTIVESTATE READERS AND AS AN EXAMPLE TO SHOW YOU YOUR CYPHER IS NOT UNBREAKABLE

I EXPECT THIS MESSAGE TO BE QUICKLY DECRYPTED AND THE PLAINTEXT POSTED BACK ON ACTIVESTATE TO POSTER PLEASE PUT A NEWLINE AFTER ANY NL YOU SEE

BY DETERMINING THE GREATEST COMMON DIVISOR OF THE DIFFERENCE BETWEEN ANY TWO CODES ONE CAN EASILY DETERMINE WHAT THE VALUE OF YOUR RANNUMBER WAS

AS GABRIEL POINTED OUT THE CHALLENGE IS TO DETERMINE THE MAPPING BETWEEN THE CODES AND THE LATIN LETTER KNOWING THE FREQUENCY OF USE OF VARIOUS LETTERS AND COMMON WORDS ESPECIALLY SHORT ONES

REGARDS

RODNEY DRENTH

Fouad Teniou (author) 14 years, 3 months ago  # | flag

Thank you Genellina,

I would like to inform you that using a key for encryption is extremely important, and I used the ran_number and my_list for the purpose( creating the key) , and I would like to thank you again for referring to the Muslim Mathematician Al-Kindi

Fouad Teniou (author) 14 years, 3 months ago  # | flag

To Andreas Tawn,

I noticed an encrypted message left by Rodney Drenth, but it did not make sense to me, because every message encrypted needs a key for every letter in the alphabet before you can decrypt the text.

And if you are willing to take a challenge I can always leave you a message which I will write myself, and you try to prove me wrong.

Rodney Drenth 14 years, 3 months ago  # | flag

Fouad,

Andreas has correctly decrypted the message that I had posted. He did so using only the information in the post. I did not supply him with any key or other information.

The last sentence is incomplete, due to an omission on my part. I wanted to say: Knowing the frequency of use of various letters and common words, especially short ones, is the key.

Finally, Fouad, your lack of understanding never ceases to amaze me.

Andreas Tawn 14 years, 3 months ago  # | flag

What Rodney said is correct, I didn't have any assistance or the encrypting key. But feel free to post some encrypted text of your own and I'll have a go at decrypting it.

I've posted the code I used below. The important part is the order of the characters in fMap.

I started with the standard English character frequency table then swapped pairs of characters as words started to appear. Obviously, as the character frequency in Rodney's message is unique, the substitution order in fMap will only work with this text. This isn't a generalised decryption tool.

from collections import defaultdict

data = [] # Too many characters for one post. Insert the list from Rodney's post @5

fMap = [" ", "E","T","N","A","O","S","R","L","I","D",
        "C","H","U","Y","P","G","M","F","B","W","V",
        "K","X","Q","J","Z"]

def sortByFrequency(counts):
    c = []
    for i in counts:
        c.append((i, counts[i]))
    c.sort(cmp=lambda x,y: cmp(y[1], x[1]))
    return [x[0] for x in c]

def getFrequencies():    
    freqs = defaultdict(int)
    for c in data:
        freqs[c] += 1
    return freqs

frequencies = sortByFrequency(getFrequencies())
print "".join(fMap[frequencies.index(i)] for i in data).replace(" NL ", "\n")
Fouad Teniou (author) 14 years, 3 months ago  # | flag

Thank you,

I would like you to prove me wrong and try to brake Code_Fouad_Teniou ( encrypted message), which I wrote myself and saved a copy on a CD. And unless you prove me wrong, there is no need for other comments.

[31845, 65456, 17693, 12386, 61918, 26538, 30076, 61918, 26538, 30076, 31845, 65 456, 54842, 49535, 31845, 28307, 38921, 31845, 31845, 44228, 38921, 19462, 38921 , 31845, 28307, 31845, 30076, 12386, 61918, 26538, 65456, 61918, 26538, 54842, 4 9535, 58380, 26538, 30076, 31845, 35383, 31845, 17693, 38921, 58380, 31845, 3184 5, 65456, 31845, 54842, 49535, 38921, 47766, 31845, 65456, 31845, 44228, 38921, 19462]

Fouad Teniou (author) 14 years, 3 months ago  # | flag

PS.

I have increased the ran_number = random.randint(1,9999)

And I added extra characters ‘0123456789 , . ;

Fouad Teniou (author) 14 years, 3 months ago  # | flag

And I added extra characters [0123456789 , . ;]

Andreas Tawn 14 years, 3 months ago  # | flag

Why have you felt the need to add non-latin characters to your input? To make it harder to decrypt?

You must be aware that the strength of a good encryption scheme is independent of its input data. If your method can't encrypt long (500+ characters), simple English text without punctuation then it can't be described as strong.

I'll invite you to take a number of English words (100+), separated by spaces, encrypt them using your method and post the resulting list here.

Fouad Teniou (author) 14 years, 3 months ago  # | flag

I would like to remind you that I made it clear in my last comment, that unless you can decrypt my encrypted message, there is no need for your comments.

However, you should know that I made a statement that no one can brake Code_Fouad_Teniou and you stated that you can do in less than 10mn.

I will be waiting…………………………forever,

PS.

My message decryption is available on my CD for you and others whenever you made an apology for your statement.

Regards

Fouad Teniou

Fouad Teniou (author) 14 years, 3 months ago  # | flag

I just realised that you do not have any programs added to ASPN, thus I would like to let you know that I do have enemies trying to put me off writing python code and the Original Scottish and Chinese Air Force are aware of them and watching them at every level including the place where I live.

Fouad Teniou

Gabriel Genellina 14 years, 3 months ago  # | flag

A single and very short message, containing a few letters alone, cannot be deciphered, even for very trivial encodings. Longer messages, or repeatedly using the same key for short ones, increase the probability of the code being deciphered.

A good code is hard to decipher EVEN when used on a long text.

In message #5 above, a moderately long message was promptly decoded. I would never use Code_Fouad_Teniou or a similar technique for anything serious, but if you do, be aware of its great limitations.

In the short story The Gold-Bug, by Edgar Allan Poe, a guy finds a treasure by solving a message encoded exactly like yours; you may find it interesting.

Gabriel Genellina 14 years, 3 months ago  # | flag

This is what I got analyzing the encoded message using a similar program as Andreas Tawn above:

" AT,NL.NL. ASK ME  HERE M .,NLANLSK_L. _ TE_  A SKED A HER"

(looks like NL means \n). It's a short message and one can only guess the missing _ characters. Probably a second message of the same length would be enough to decipher it completely.

Fouad Teniou (author) 14 years, 3 months ago  # | flag

Thank you for trying to decrypt my message, but unfortunately you were wrong. And this is not my message.

And I would like to post for you a longer message, since you think that you will have a better chance of solving the message, by increasing the probability, and I promise you again that it is impossible to decrypt Code_Fouad_Teniou , but you can always try.

Fouad Teniou (author) 14 years, 3 months ago  # | flag

Here a new longer message,

[9591, 278055, 268467, 278055, 354759, 28767, 278055, 9591, 278055, 9591, 143823 , 383523, 278055, 134235, 9591, 278055, 124647, 249291, 47943, 278055, 115059, 3 73935, 124647, 278055, 76707, 182175, 373935, 268467, 19179, 9591, 373935, 32599 5, 278055, 38355, 278055, 38355, 373935, 230115, 258879, 278055, 162999, 220527, 278055, 182175, 38355, 316407, 28767, 239703, 278055, 306819, 9591, 239703, 316 407, 28767, 38355, 316407, 28767, 57531, 201351, 67119, 258879, 278055, 364347, 239703, 278055, 182175, 278055, 9591, 95883, 124647, 373935, 278055, 239703, 143 823, 278055, 268467, 373935, 325995, 278055, 383523, 325995, 278055, 220527, 278 055, 57531, 278055, 38355, 373935, 220527, 278055, 306819, 220527, 278055, 29723 1, 278055, 67119, 278055, 9591, 278055, 220527, 268467, 28767, 364347, 325995, 3 73935, 95883, 325995, 278055, 268467, 38355, 373935, 143823, 278055, 268467, 239 703, 373935, 9591, 278055, 143823, 383523, 278055, 134235, 278055, 249291, 32599 5, 278055, 268467, 38355, 28767, 76707, 278055, 268467, 278055, 373935, 325995, 373935, 230115, 325995, 278055, 239703, 316407, 28767, 278055, 162999, 268467, 2 39703, 278055, 57531, 373935, 57531, 28767, 306819, 19179, 38355, 239703, 278055 , 124647, 373935, 230115, 258879, 278055, 162999, 57531, 201351, 278055, 325995]

Fouad Teniou (author) 12 years, 8 months ago  # | flag

A switch to C# and a new link

http://archive.msdn.microsoft.com/fouadteniou

Created by Fouad Teniou on Thu, 7 Jan 2010 (MIT)
Python recipes (4591)
Fouad Teniou's recipes (37)

Required Modules

Other Information and Tasks