Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by ChompIV · May 20, 2017 at 04:20 PM · javascriptfilehighscoressystem.ioencryption

Is there a way to encrypt/lock a File.CreateText file? (its my highscore)

So my high score system is a little weird. I use the File.CreateText thing to do it, here is the script if you need it: (Java and its called ScoreSave) import System.IO;

 var fileName = "hs.data";
 var ScoreAmount : int;
 
 var HighScore : int;
 
 function Start (){
     HighScore = ScoreLoad.CompareScore;
     ScoreAmount = GlobalScore.CurrentScore;
     if (ScoreAmount >= HighScore){
         var OurFile = File.CreateText(fileName);
         OurFile.WriteLine (ScoreAmount);
         OurFile.Close();
     }
 }

Also here is my script for loading the score if that is needed for explanation (java and its called ScoreLoad):

 import System.IO;
 
 var fileName = "HS.data";
 var ScoreLoad : String;
 var HighScoreDisplay : GameObject;
 
 var line : String;
 
 static var CompareScore : int;
 
 function Start(){
     var sr : StreamReader = new StreamReader(fileName);
 
     line = sr.ReadLine();
     while (line != null){
         ScoreLoad = line;
         line = sr.ReadLine();
 
     }
     sr.Close();
 
     HighScoreDisplay.GetComponent.<Text>().text = "" + ScoreLoad;
 
     CompareScore = int.Parse(ScoreLoad);
 }

My question is how do I make it so in the final build, players wont just be able to go to the game files, go into the file called hs.data and change their high score to a high number aka cheat? How do I like encrypt it or lock it or make it permanently read only or something? Anything helps, thank you! Also it needs to be able to save the highscore when it gets a new one so would read only not work? Help please. Thanks.

Comment
Add comment · Show 1
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image RobAnthem · May 20, 2017 at 06:31 PM 0
Share

I'm not sure the library or exact method of JavaScript since I personally would never willingly write JS, but if you know any kind of C#, then this would be how $$anonymous$$SDN how-to-encrypt-and-decrypt-a-file

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by toddisarockstar · May 20, 2017 at 06:38 PM

encriptions and keys is a very big question. i guess it would simply depend on the security you need. I wrote a simple encryption for you. its not as secure as some advanced techniques or preshared keys but this should be enough to prevent users from editing or even knowing what they are looking at.

this script i wrote for you changes numbers into letters based on your key.

also it adds two additional numbers for every one number. the new set of three numbers must all add together properly so a user can't just change any one character or two characters in the encrypted string or you know its been tampered with. Additionally with this script you could incorporate the user's name into the key so people couldn't share files. just make sure every letter in the key is unique.

 public var score:int;
     public var output:String;
      var key:String;
     var err:boolean;
     
     function Start(){
         //key represents numbers 0 through 9;
         key = "qwertyuiop";
 
         // example number
         score=1258746;
         print ("original:" + score);
 
         output=scramble (score);
         print ("scrambled number: " + output);
         print ("returned:"+unscramble (output));
     }
 
 
      function scramble(sint:int):String{
         var i:int;
         var i2:int;
         var i3:int;
 
         var s1:String="";
         var s2:String="";
         s1 = sint.ToString();
 
         i = s1.Length;
     
         while (i>0) {i--;
             int.TryParse(s1.Substring(i,1),i2);    
             i3=UnityEngine.Random.Range(0,i2);
             s2=s2+keyed(i3);
             i3=i2-i3;
             s2=s2+keyed(i3);
             s2=s2+keyed(i2);
         }
         return s2;
     }
 
     // change number into letter
     function keyed(i:int):String{
         return key.Substring (i, 1);}
 
     //change letter into number
     function unkey(s:String):int {
         var i2:int=-1;
         var i:int = key.Length;
         while (i>0) {i--;
             if(s==key.Substring(i,1))
                 i2=i;
                 }
         if(i2==-1){err=true;return 0;}else{return i2;}
         }
 
     function unscramble(s:String):int{
         var i: int;
         var i2: int;
         var i3: int;
         var i4: int;
 
         var s2:String ="";
         err = false;
     
                 i = s.Length;
                 
                 while (i>0) {i=i-3;
             if(i<0){err=true;}else{
             i2=unkey(s.Substring(i+2,1));
             i3=unkey(s.Substring(i+1,1));
             i4=unkey(s.Substring(i,1));
             if(i3+i4==i2){s2=s2+i2.ToString();}else{err=true;}
             }}
         if(err){return 0;print ("tampered numbers");}
         else{int.TryParse(s2,i);
                 return i;}
     
         }

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

How do I make it so players can't edit the file but the game can? File.CreateText 2 Answers

How would I transfer these into PlayerPrefs? 0 Answers

Help writing to a file every update/frame (JS) 1 Answer

Can someone help me fix my Javascript for Flickering Light? 6 Answers

[C#] Saving settings to a local file and reading from it at runtime 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges