This is definitively a highly debatable topic. Most people will argue that Javascript obfuscation, or just obfuscation in general has no purpose in this world. And I actually think they are right.
However, rules are there to be broken, and sometime you would actually want something like this to keep the “basic copy pasters” away from your stuff. But how would you accomplish that in an easy and simple way?
Most people just base64 encode / decode, or use eval or even unescape on their strings i Javascript. It works good but the kiddies sometimes get through. So when you want a little higher level of protection, you might want to try this, which I wrote for a friend.
It’s just two simple PHP functions to include in your page. Then you can use the “protected_echo” function to echo out a javascript element with all the code necessary to decrypt the content on the client side. It’s still easy for anyone with a little knowledge of Javascript / HTML to get to the guts of this, but if you have such highly confidential material laying around on the public internet, you should really revise your strategy!
<html>
<head>
<title>Protected demo!</title>
</head>
<body>
<?php//Start copying the functions here.function protect($input){$tmp='';$length=strlen($input);for($i=0;$i<$length;$i++)$tmp.='%'.bin2hex($input[$i]);returnstrrev($tmp);}function protected_echo($input){echo"<script language=\"javascript\">
eval(unescape('". protect("document.write(unescape(\"".protect($input)."\".split(\"\").reverse().join(\"\")))")."'.split(\"\").reverse().join(\"\")));
</script>";}//End copy here.?>
<p>Some random HTML stuff or anything else here...</p>
<?php//Down here we are using the protected_echo function.
protected_echo("Protection test!");?>
</body>
</html>
And the resulting HTML code on the client side will be like this:
<html><head><title>Protected demo!</title></head><body><p>Some random HTML stuff or anything else here...</p><script language="javascript">eval(unescape('92%92%92%22%22%82%e6%96%f6%a6%e2%92%82%56%37%27%56%67%56%27%e2%92%22%22%82%47%96%c6%07%37%e2%22%52%53%03%52%73%23%52%63%66%52%73%43%52%63%53%52%63%33%52%73%43%52%63%93%52%63%66%52%63%56%52%23%03%52%73%43%52%63%53%52%73%33%52%73%43%52%23%13%22%82%56%07%16%36%37%56%e6%57%82%56%47%96%27%77%e2%47%e6%56%d6%57%36%f6%46%'.split("").reverse().join("")));</script></body></html>
Sorry for no posts the last couple of days. I’ve been busy doing all kinds of weird things ;)
I just wanted to share this very simple little class I just made for using the Speech API built into Windows.
It is already fairly simple very simple to use, but I’m the kind of guy who likes everything to be my way. So I wrote this to “decrapify” the API so I just have two simple properties and some simple functions / subs to access it.
Enjoy! :)
Imports System.SpeechPublicClass SpeechSynthesis
Private voiceSynthesis AsNew Synthesis.SpeechSynthesizer()Private voiceRate AsInteger=-2Private voiceVolume AsInteger=75'''''' Used while initializing this object. Called automaticly when making a new instance like: Dim o as new SpeechSenthesis().''''''PublicSubNew()
voiceSynthesis.Volume= voiceVolume
voiceSynthesis.Rate= voiceRate
voiceSynthesis.SelectVoice(voiceSynthesis.GetInstalledVoices()(0).VoiceInfo.Name)EndSub'''''' Used to start speaking a string asynchronously.'''''' <span> </span>The text to speak as a string.''' A boolean value representing whatever to cancel other speaking instances of this object or throwing a'''PublicSub speakAsynchronously(ByVal text AsString, OptionalByVal forceSpeak AsBoolean=False)If forceSpeak ThenIf voiceSynthesis.State= Synthesis.SynthesizerState.ReadyThen
voiceSynthesis.SpeakAsync(text)ElseIf voiceSynthesis.State= Synthesis.SynthesizerState.SpeakingThen
voiceSynthesis.SpeakAsyncCancelAll()
voiceSynthesis.SpeakAsync(text)EndIfElseIf voiceSynthesis.State= Synthesis.SynthesizerState.ReadyThen
voiceSynthesis.SpeakAsync(text)ElseThrowNew Exception("Already speaking.")EndIfEndIfEndSub'''''' Used to start speaking a string synchronously.'''''' The text to speak as a string.''' A boolean value representing whatever to cancel other speaking instances of this object or throwing a'''PublicSub speakSynchronously(ByVal text AsString, OptionalByVal forceSpeak AsBoolean=False)If forceSpeak ThenIf voiceSynthesis.State= Synthesis.SynthesizerState.ReadyThen
voiceSynthesis.Speak(text)ElseIf voiceSynthesis.State= Synthesis.SynthesizerState.SpeakingThen
voiceSynthesis.SpeakAsyncCancelAll()
voiceSynthesis.Speak(text)EndIfElseIf voiceSynthesis.State= Synthesis.SynthesizerState.ReadyThen
voiceSynthesis.SpeakAsync(text)ElseThrowNew Exception("Already speaking.")EndIfEndIfEndSub'''''' Stops the current asyncronously speaking from this object.''''''PublicSub stopSpeakingAsynchronously()If voiceSynthesis.State= Synthesis.SynthesizerState.SpeakingThen
voiceSynthesis.SpeakAsyncCancelAll()EndIfEndSub'''''' Pauses the currentasyncronously speaking from this object.''''''PublicSub pauseSpeaking()If voiceSynthesis.State= Synthesis.SynthesizerState.SpeakingThen
voiceSynthesis.Pause()EndIfEndSub'''''' Resumes speaking.''''''PublicSub resumeSpeaking()If voiceSynthesis.State= Synthesis.SynthesizerState.PausedThen
voiceSynthesis.Resume()EndIfEndSub'''''' Sets the volume of this object. Ranging from 0 - 100. Standard is 75.''''''''''''PublicPropertyvolumeAsIntegerGetReturn voiceVolume
EndGetSet(ByVal value AsInteger)If value > 100Then
voiceVolume =100ElseIf value < 0Then
voiceVolume =0Else
voiceVolume = value
EndIf
voiceSynthesis.Volume= voiceVolume
EndSetEndProperty'''''' Used to define the voicerate of this object. Ranging from -10 to 10. Standard is -2.''''''''''''PublicPropertyrateAsIntegerGetReturn voiceRate
EndGetSet(ByVal value AsInteger)If value > 10Then
voiceRate =10ElseIf value < -10Then
voiceRate =-10Else
voiceRate = value
EndIf
voiceSynthesis.Rate= voiceRate
EndSetEndProperty'''''' Get's a list of available voices as an array, when you don't need all the BS ;)'''''''''PublicFunction getAvailableVoiceNames()AsArrayDim voiceList(voiceSynthesis.GetInstalledVoices.Count-1)AsStringDim counter AsInteger=0ForEach voice As Speech.Synthesis.InstalledVoice In voiceSynthesis.GetInstalledVoices
voiceList(counter)= voice.VoiceInfo.Name
counter +=1NextReturn voiceList
EndFunction'''''' Get's a list of available voices as a list of VoiceInfo when you need everything.'''''''''PublicFunction getAvailableVoices()As List(Of Synthesis.VoiceInfo)Dim voiceList AsNew List(Of Synthesis.VoiceInfo)ForEach voice As Speech.Synthesis.InstalledVoice In voiceSynthesis.GetInstalledVoices
voiceList.Add(voice.VoiceInfo)NextReturn voiceList
EndFunction'''''' Set's the voice based on a name. Standard when creating this object is just the first one available.'''''''''PublicSub setVoiceByName(ByVal name AsString)ForEach voice As Speech.Synthesis.InstalledVoice In voiceSynthesis.GetInstalledVoicesIf voice.VoiceInfo.Name.Trim= name.TrimThen
voiceSynthesis.SelectVoice(name.Trim)ExitSubEndIfNextThrowNew Exception("The voice isn't installed on this computer.")EndSubEndClass
Just put this inside a new class called SpeechSynthesis.vb and begin using it. Everything should be pretty self exploratory, especially with the added XML documentation (okay overkill but I was bored).
Oh and by the way. You will need to add a reference to system.speech like this:
I’m back once again. Sorry for being a little late with this post. I had a whole bunch of other things in my head, so I almost forgot posting this. I’m so sorry!
Anyway, let’s get back on the track! Literally! ;)
Let’s start with some background information. I’ve always had this strange dream about a robot, that could run around in my room and perform small tasks automatically while I was gone. And afterwards recharge itself somewhere in the corner of the room.
Lately I’ve become quite good with robotics, and other peripherals. So now I want to make this dream come true, one small step at a time. But in my way, there is several problems to be faced. (And hopefully solved).
Navigating around.
Performing the actual task(s).
Recharging autonomously.
Other functions?
The first problem is navigation. I have looked at various methods, differing from ultrasonic sensors to infrared beacons.
Especially the thing with IR beacons looks good, and some other guys have used it for their own robotics.
But just as good as IR looks, I think it’s quite expensive. The robotic Lego cleaner is using a homebuilt IR transmitter and an Infrared seeker for the NXT robot.
This was actually my first thought, but complete with import taxes and everything, I think that $130 is way to much for a single Lego sensor.While the IR beacons from Pololu.com looks fantastic, they also have a pricetag of $49 dollars excluding shipping, which is still a little to much in my opinion. Maybe if this doesn’t work out, I will try them
.But while thinking about all this I remembered something called “hall effect sensors”. They are basically small sensors, used in everyday electronics, which have the ability to sense magnetic fields. Not like a compass, more like when you keep it close to a fridge magnet.
With this new (and awesome) discovery, the idea quickly took shape. First I was thinking about maybe using something like an electric cable in the floor which would when form a magnetic field around it, hopefully big enough for the hall effect sensors to catch on.
While I haven’t completely ruled out this way of doing things yet, I decided to go for something more simple.
But what is simple, strong, reliable and generates a strong magnetic field around it? Magnets of course! But not your everyday magnets. Neodymium magnets is the way to go!
I have yet to receive these magnets from Ebay, but I really hope they will be here soon so I can start putting them down under the carpet.
Let’s move on with the project!
Parts list:
3x A1302 Linear hall effect sensor
3x LED’s
1x Arduino (I used Duemilanove)
A breadboard with jumper wires
A really strong magnet. A couple of hundreds if you plan on laying them down into the floor like me ;)
And magnets can be bought here: http://shop.ebay.com/?_kw=rare%20earth%20magnets&_fcid=57&_jgr=1&_localstpos=&_stpos=&gbr=1
Let’s begin by wiring it all up. Here I was trying to make a fancy little circuit diagram, but I failed in lack of good software, and the circuit is so simple. So I hope it will work out.
Start by connecting the 3 hall effect sensors to both ground and 5v on the specified pins.
(Datasheet available here: http://www.allegromicro.com/en/Products/Part_Numbers/1301/1301.pdf )
When connect the output from each sensor to the Arduino’s analog inputs. (I use 0,1,2 in my program).
Proceed and place the LED’s somewhere near each sensor. Connect the cathodes to ground, and anodes to Arduino I/O pin 12, 11 and 10.
In my setup, I have placed the LED on 12, beside the sensor on 0, and the LED on 11, beside the sensor on 1. And last the LED on 10, beside the sensor on 2.
Now you just need to load up this sketch, and when move a magnet around near the sensors. If the LED’s doesn’t light up, try and watch the console output, and check your setup. Also try flipping the magnet itself around, as the sensors is sensitive to each pole.
//Defines 3 variables. One for holding each sensor.int rawA =0;int rawB =0;int rawC =0;void setup(){//Used for debugging only.
Serial.begin(9600);//Defines the 3 LED's as outputs.
pinMode(10, OUTPUT);
pinMode(11, OUTPUT);
pinMode(12, OUTPUT);}void loop(){// Here we are reading the 3 sensors into the variables.
rawA = analogRead(0);
rawB = analogRead(1);
rawC = analogRead(2);//The next block of code can just be removed. This is only for debugging.
Serial.print("A: ");
Serial.print(rawA);
Serial.println();
Serial.print("B: ");
Serial.print(rawB);
Serial.println();
Serial.print("C: ");
Serial.print(rawC);
Serial.println();
Serial.println();//Here we actually calculates a direction. It's quite simple. Just ask me if you don't get the concept ;)
Serial.print("Direction: ");if(rawA-10> rawB && rawC-10> rawB){//This if goes of when right on track.
Serial.print("Right on track!");//This is just for LED's. Replace with motor control or whatever.
digitalWrite(10, LOW);
digitalWrite(11, HIGH);
digitalWrite(12, LOW);}elseif(rawA+10< rawB){//This if goes of when the magnet is being detected to the right. That means that the robot should go right.
Serial.print("Attack the right flank! Aaaarhg!");//This is just for LED's. Replace with motor control or whatever.
digitalWrite(10, LOW);
digitalWrite(11, LOW);
digitalWrite(12, HIGH);}elseif(rawC+10< rawB){//This if is fired when magnettrack is to the left.
Serial.print("Move all units to the left!");//This is just for LED's. Replace with motor control or whatever.
digitalWrite(10, HIGH);
digitalWrite(11, LOW);
digitalWrite(12, LOW);}elseif((rawB+rawC)/2+10< rawA){//INFORMATION! This if block, is just for showing of. It detects if the magnettrack is getting a little of center to the left. Can be
Serial.print("Magnettrack is a little the left!");//This is just for LED's. Replace with motor control or whatever.
digitalWrite(10, HIGH);
digitalWrite(11, HIGH);
digitalWrite(12, LOW);}elseif((rawB+rawA)/2+10< rawC){//INFORMATION! This if block, is just for showing of. It detects if the magnettrack is getting a little of center to the right. Can be
Serial.print("Magnettrack is a little to the right!");//This is just for LED's. Replace with motor control or whatever.
digitalWrite(10, LOW);
digitalWrite(11, HIGH);
digitalWrite(12, HIGH);}else{//Down here is when no magnets is being detected. If you know there is a magnet try debugging//Or changing the magnet difference values. If nothing works, check your circuit or contact me on www.hsp.dk
Serial.print("No magnettrack detected! :(");//This is just for LED's. Replace with motor control or whatever.
digitalWrite(10, LOW);
digitalWrite(11, LOW);
digitalWrite(12, LOW);}//Writes two blank lines while debugging. Just for a pretty console ;)
Serial.println();
Serial.println();}
About Henrik
Henrik Pedersen has been programming since 2007 where he started out with Visual Basic, and he is still continuing to learn new skills each day. His interests vary all the way
from advanced robotic projects, to about every flavor of beautiful Danish women. He's mostly developing in .NET but knows a variety of other languages, and has experience
with even more.