I haven't written a blog for a long time. I 've written some bad stuff before. Sorry. This time I will introduce some new features of quick-x quick-cocos2d-x.

Source: Internet
Author: User

Quick-x Data Encryption

I. Data Encryption

As long as quick encapsulation is used

Local crypto = require ("framework. crypto") -- algorithm encryption and decryption

To make



Function crypto. encryptxxtea (plaintext, key)
Plaintext = tostring (plaintext)
Key = tostring (key)
Return cccrypto: encryptxxtea (plaintext, String. Len (plaintext), key, String. Len (key ))
End


This is something in the framework. If you are interested, take a look.



Here, my encrypted data is decrypted, read, and encrypted, and saved only when modified, so that the encryption field cannot be changed for the Ghost artifact and so on.


Local key_coin = "coin"

Local encodecoin = crypto. encryptxxtea (0, key_coin) -- gold coins


-- Gold coin ----------

Local writecoin = function ()

Userdefault: setstringforkey (key_coin, encodecoin)

End


Function gamedata: getcoin ()

Return tonumber (crypto. decryptxxtea (encodecoin, key_coin ))

End


Function gamedata: setcoin (value)

Local coin = self: getcoin () + Value

If coin <0 then returnend


Encodecoin = crypto. encryptxxtea (coin, key_coin)

Writefuncs [key_coin] = writecoin


Eventmanager: dispatchevent ({name = event_data, kind = player. coin, value = coin })

Return coin

End



I haven't written a blog for a long time. I 've written some bad stuff before. Sorry. This time I will introduce some new features of quick-x quick-cocos2d-x.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.