Thursday, December 31, 2020

Setting up Xcode for Apache Cordova

Prerequisites for Apache Cordova iOS is to have Xcode installed. For the latest version of Xcode, we need to add the Developer bin to the path so that all the tools can be accessed from the Terminal.
➜ vim ~/.zshrc
export PATH="/Applications/Xcode.app/Contents/Developer/usr/bin:$PATH"
Once we add the path to Xcode tools, we can install the corodova tool.
➜ npm install -g ios-deploy
If success, it should give a log like below.
changed 1 package, and audited 1 package in 12s

found 0 vulnerabilities
Open the app workspace in Xcode, click run to see the app running.

Monday, December 14, 2020

Mac Double-Click Speed

If double click is always showing up the edit name option, then this can be rectified by checking the Pointer Control options under Accessibility. Reducing the Double-click speed should work.

Sunday, December 13, 2020

Hello World

This is my approximately fifth attempt to keep a blog together. Hope this time things goes well. Disclaimer: All thoughts expressed are my own and not that of my employer.

Monday, February 10, 2020

XOR encryption and decryption with Swift

In most iOS apps we might have API key constants. Instead of keeping them as plain text, we can use XOR encrypted value and decrypt on app launch.
/// XOR encrypt plain text with a key.
/// - Parameters:
/// - plainText: A plain text for encryption.
/// - withKey: Encryption key.
/// - Returns: An array containing encrypted bytes
func xorEncrypt(_ plainText: String, withKey: String) -> [UInt8] {
var encrypted: [UInt8] = []
if plainText.isEmpty {
return []
}
let text: [UInt8] = Array(plainText.utf8)
let key: [UInt8] = Array(withKey.utf8)
let len = key.count
text.enumerated().forEach { idx, elem in
encrypted.append(elem ^ key[idx % len])
}
return encrypted
}

/// XOR decrypt cipher text with a key.
/// - Parameters:
/// - cipherText: A cipher text for decryption.
/// - withKey: Decryption key.
/// - Returns: The decrypted string.
func xorDecrypt(_ cipherText: [UInt8], withKey: String) -> String {
var decrypted: [UInt8] = []
if cipherText.count == 0 {
return ""
}
let key: [UInt8] = Array(withKey.utf8)
let len = key.count
cipherText.enumerated().forEach { idx, elem in
decrypted.append(elem ^ key[idx % len])
}
return String(bytes: decrypted, encoding: .utf8)!
}
Using the above xorEncrypt function will give an array of numbers which we can add as a constant. On app launch, use the xorDecrypt function with the array value and the same key to get the plain text back.

Change the default prompt in Terminal

The latest version of macOS uses zsh as the shell. To change the prompt in the Terminal we can do the following.

1. Install oh-my-zsh which provides many enhancements to the zsh.
2. Install spaceship theme.
npm install -g spaceship-prompt
3. Set the theme to spaceship and the prompt symbol to λ from the default % by add the below in the .zshrc file
ZSH_THEME="spaceship"
SPACESHIP_CHAR_SYMBOL='λ '
# Set Spaceship ZSH as a prompt
autoload -U promptinit; promptinit
prompt spaceship
4. Source the configuration source ~/.zshrc or relaunch the terminal. We will have our updated prompt in the Terminal.