Dans la catégorie inutile donc indispensable, je vous présente le brouilleur de texte:
Une théorie dit que l'on peut lire un texte dont les lettres de chacun des mots qu'il contient sont mélangées, tant que la 1ère et la dernière lettre de chaque mot est à sa place.
Pour vérifier cette théorie, je vous propose ce petit script python avec une interface graphique légère en TK, qui transpose ce que vous écrivez en haut en texte "brouillé".
Attention, je vous avait prévenu: c'est inutile.
Source / Exemple :
# -*- coding: latin -*-
from Tkinter import *
import random, re
def schrmble(word):#mix the word
charList=[]#initialize the characters list
if (len(word)<=3):#if the word is smaller than 4 characters
return word#then nothing to do
charDeb=word[0:1]#isolating the first character
charEnd=word[len(word)-1:len(word)]#isolating the last character
word=word[1:len(word)-1]#word = it center
newWord=""
for char in word:#for each character of the word
charList.append(char)#we append it to the character list
while (len(charList)>0):#then we randomy choose a character to append to the newWord
newWord=newWord+charList.pop(random.randint(0, len(charList)-1))
return charDeb+newWord+charEnd#we return the complete newWord: 1stchar+newWord+lastchar
def key(event):#when the user release a key in textInput
wholeText=textInput.get(1.0, END)#wholeText contains the text typed in the text area
exp=re.compile("[^a-zA-Zàâçéèêîïôöïû]",re.U)#new regular expression that search each non alphabetic character
res=exp.search(wholeText)#apply a regular search with the expression
mixedText=schrmble(wholeText[0:res.start()])#mix the first word
while (res.end()<len(wholeText)):#while their are possible separators to find
mixedText=mixedText+wholeText[res.start():res.end()]#append the separator to the mixed text
oldEnd=res.end()#save the old end index
res=exp.search(wholeText, oldEnd)#perform a new search
mixedText=mixedText+schrmble(wholeText[oldEnd:res.start()])#add the mixed word to the mixed text
textOutput.delete(1.0, END)#clear the text output area
textOutput.insert(END,mixedText)#insert the new mixed text
root=Tk()#create the main window
root.title("Brouilleur de texte (par VyCHNou)")
pHaut=Frame(root)
pBas=Frame(root)
pHaut.pack(side=TOP, fill=BOTH, expand="yes")
pBas.pack(side=BOTTOM, fill=BOTH, expand="yes")
textInput = Text(pHaut,bg="lightblue", fg="black", font=14,width=40,height=10,wrap=WORD)#create the text
textInput.pack(anchor=NW, side=LEFT, fill=BOTH, expand="yes")#use the pack layout to attach the entry to the windows
textInput.bind("<KeyRelease>", key)#bind the entry to the callback "key"
textInput.focus()#give the entry the focus
textOutput = Text(pBas,bg="lightgreen", fg="black", font=14,width=40,height=10,wrap=WORD)#create the text
textOutput.pack(anchor=NW, side=LEFT, fill=BOTH, expand="yes")#use the pack layout to attach the entry to the windows
scrollbarInput = Scrollbar(pHaut)#add a scrollbar for the textInput
scrollbarInput.pack(side=RIGHT, fill=Y, anchor=NE)
scrollbarInput.config(command=textInput.yview)#configure the scrollbar
scrollbarOutput = Scrollbar(pBas)#add a scrollbar for the textInput
scrollbarOutput.pack(side=RIGHT, fill=Y, anchor=SE)
scrollbarOutput.config(command=textOutput.yview)#configure the scrollbar
root.mainloop()#let's run the window
Conclusion :
Dans la ctoiraége itunile donc iaebispdnnsle, je vuos pnrestée le bleuoulrir de ttexe:
Une torihée dit que l'on puet lire un txtee dnot les letrtes de cauchn des mtos qu'il cnotinet snot meéaélgns, tant que la 1ère et la dnèreire lrette de cauqhe mot est à sa pcale.
Pour vfreéiir cette toérhie, je vous psoproe ce piett scprit phyotn aevc une icretnafe guarhpiqe lrgéèe en TK, qui tpoasnrse ce que vuos éicverz en haut en texte "bllrouié".
Ationtetn, je vuos avait prnvéeu: c'est inliute.
Vous n'êtes pas encore membre ?
inscrivez-vous, c'est gratuit et ça prend moins d'une minute !
Les membres obtiennent plus de réponses que les utilisateurs anonymes.
Le fait d'être membre vous permet d'avoir un suivi détaillé de vos demandes et codes sources.
Le fait d'être membre vous permet d'avoir des options supplémentaires.